Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/mrkiven/ecache
:clap::clap: Integrate cache(redis) [flask etc.] with SQLAlchemy.
https://github.com/mrkiven/ecache
cache flask python sqlalchemy
Last synced: 23 days ago
JSON representation
:clap::clap: Integrate cache(redis) [flask etc.] with SQLAlchemy.
- Host: GitHub
- URL: https://github.com/mrkiven/ecache
- Owner: MrKiven
- License: mit
- Created: 2016-11-10T12:47:20.000Z (almost 8 years ago)
- Default Branch: master
- Last Pushed: 2022-12-26T19:59:21.000Z (almost 2 years ago)
- Last Synced: 2024-08-09T12:51:27.829Z (3 months ago)
- Topics: cache, flask, python, sqlalchemy
- Language: Python
- Homepage: https://git.io/vHrQ1
- Size: 36.1 KB
- Stars: 29
- Watchers: 4
- Forks: 6
- Open Issues: 3
-
Metadata Files:
- Readme: README.rst
- License: LICENSE
Awesome Lists containing this project
README
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 SQLAlchemyfrom 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/