Cache integration with sqlalchemy.
Project description
Run test
make unittest
Installation / Rquirements
pip intall ecache
Usage
With Flask Integrate
See example
With Pure SQLAlchemy model Integrate
# -*- 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()
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
ecache-0.0.2.tar.gz
(11.4 kB
view details)
File details
Details for the file ecache-0.0.2.tar.gz
.
File metadata
- Download URL: ecache-0.0.2.tar.gz
- Upload date:
- Size: 11.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | bd7b3d9aa529477ca76a0ef39316e506257a79c8fdb9d111dd4e95327ca1d9d2 |
|
MD5 | a3e5eac299e5d8446648e6dea4c6acd1 |
|
BLAKE2b-256 | 4242f22bd61448cf397c4665be508193c52062d3bf00ac32143f0780faf0156d |