All Projects → MrKiven → Ecache

MrKiven / Ecache

Licence: mit
👏👏 Integrate cache(redis) [flask etc.] with SQLAlchemy.

Programming Languages

python
139335 projects - #7 most used programming language

Projects that are alternatives of or similar to Ecache

Data Driven Web Apps With Flask
Course demo code and other hand-out materials for our data-driven web apps in Flask course
Stars: ✭ 388 (+1285.71%)
Mutual labels:  sqlalchemy, flask
Potion
Flask-Potion is a RESTful API framework for Flask and SQLAlchemy, Peewee or MongoEngine
Stars: ✭ 484 (+1628.57%)
Mutual labels:  sqlalchemy, flask
Mini Shop Server
基于 Flask 框架开发的微信小程序后端项目,用于构建小程序商城后台 (电商相关;rbac权限管理;附带自动生成Swagger 风格的API 文档;可作「Python 项目毕设」;慕课网系列)---- 相关博客链接:🌟
Stars: ✭ 446 (+1492.86%)
Mutual labels:  sqlalchemy, flask
Flask Sqlacodegen
🍶 Automatic model code generator for SQLAlchemy with Flask support
Stars: ✭ 283 (+910.71%)
Mutual labels:  sqlalchemy, flask
Mixer
Mixer -- Is a fixtures replacement. Supported Django, Flask, SqlAlchemy and custom python objects.
Stars: ✭ 743 (+2553.57%)
Mutual labels:  sqlalchemy, flask
Flask Sqlalchemy
Adds SQLAlchemy support to Flask
Stars: ✭ 3,658 (+12964.29%)
Mutual labels:  sqlalchemy, flask
Flask Restplus Boilerplate
A boilerplate for flask restful web service
Stars: ✭ 466 (+1564.29%)
Mutual labels:  sqlalchemy, flask
Autoline
建议你使用更新的AutoLink平台
Stars: ✭ 227 (+710.71%)
Mutual labels:  sqlalchemy, flask
Flask Marshmallow
Flask + marshmallow for beautiful APIs
Stars: ✭ 666 (+2278.57%)
Mutual labels:  sqlalchemy, flask
Flask Caching
A caching extension for Flask
Stars: ✭ 582 (+1978.57%)
Mutual labels:  cache, flask
Safrs
SqlAlchemy Flask-Restful Swagger Json:API OpenAPI
Stars: ✭ 255 (+810.71%)
Mutual labels:  sqlalchemy, flask
Databook
A facebook for data
Stars: ✭ 26 (-7.14%)
Mutual labels:  sqlalchemy, flask
Flask Boilerplate
Simple flask boilerplate with Postgres, Docker, and Heroku/Zeit now
Stars: ✭ 251 (+796.43%)
Mutual labels:  sqlalchemy, flask
Enferno
A Python framework based on Flask microframework, with batteries included, and best practices in mind.
Stars: ✭ 385 (+1275%)
Mutual labels:  sqlalchemy, flask
Flask Base
A simple Flask boilerplate app with SQLAlchemy, Redis, User Authentication, and more.
Stars: ✭ 2,680 (+9471.43%)
Mutual labels:  sqlalchemy, flask
Full Stack
Full stack, modern web application generator. Using Flask, PostgreSQL DB, Docker, Swagger, automatic HTTPS and more.
Stars: ✭ 451 (+1510.71%)
Mutual labels:  sqlalchemy, flask
Eve Sqlalchemy
SQLAlchemy data layer for Eve-powered RESTful APIs
Stars: ✭ 215 (+667.86%)
Mutual labels:  sqlalchemy, flask
The Flask Mega Tutorial
📖《The Flask Mega-Tutorial》中文2018最新版📗
Stars: ✭ 221 (+689.29%)
Mutual labels:  sqlalchemy, flask
Flask Rest Jsonapi
Flask extension to build REST APIs around JSONAPI 1.0 specification.
Stars: ✭ 566 (+1921.43%)
Mutual labels:  sqlalchemy, flask
Flask Sqlalchemy Booster
Collection of utilities and decorators which add extensive querying and serializing capabilities to Flask SQLalchemy models
Stars: ✭ 5 (-82.14%)
Mutual labels:  sqlalchemy, flask

Ecache for sqlalchemy

Run test

.. code:: bash

make unittest

Installation / Rquirements

.. code::

pip install ecache

Usage

With Flask Integrate


.. code:: python

    from flask import Flask, jsonify
    from flask_sqlalchemy import SQLAlchemy

    from ecache.ext.flask_cache import CacheableMixin, query_callable, regions

    app = Flask(__name__)
    app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:////tmp/test.db'
    app.debug = True
    db = SQLAlchemy(app)

    class User(db.Model, CacheableMixin):
        """Default backend is redis and expiration time is 1 hour, default
        region name is `default`, you can override this:

            cache_regions = your_regions
            cache_label = your_label
        """

        id = db.Column(db.Integer, primary_key=True)
        name = db.Column(db.String)

    @app.route('/users')
    def all_users():
        """Result will try to get from cache first. load from db if cache miss.
        """
        users = [user.to_dict() for user in User.cache.filter()]
        return jsonify(users=users)


    @app.route('/users/<int:user_id')
    def view_user(user_id):
        """Result will try to get from cache first. load from db if cache miss.
        """
        user = User.cache.get(user_id)
        return jsonify(user.to_dict())

More detail see `example`_

.. _`example`: https://github.com/MrKiven/ECache/blob/master/ecache/ext/example.py


With Pure SQLAlchemy model Integrate

.. code:: python

# -*- coding: utf-8 -*-

import redis
from sqlalchemy import (Column, Integer, String, SmallInteger)

from ecache.core import cache_mixin
from ecache.db import db_manager, model_base

# alsosee :class:`ecache.db.DBManager`
DBSession = db_manager.get_session('test')
cache_client = redis.StrictRedis()
CacheMixin = cache_mixin()
DeclarativeBase = model_base()


class TodoListModel(DeclarativeBase, CacheMixin):
    __tablename__ == 'todo_list'
    TABLE_CACHE_EXPIRATION_TIME = 3600

    id = Column(Integer, primary_key=True)
    title = Column(String, default='')
    is_done = Column(SmallInteger, default=0)

    @classmethod
    def get_todo(cls, todo_id):
        todo = cls.get(todo_id)  # `cls.get` inherited from `CacheMixin`
        return todo

    @classmethod
    def add(cls, title):
        todo = cls(title=title)
        s = DBSession()
        s.add(todo)
        s.commit()
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].