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.3.tar.gz
(11.4 kB
view details)
File details
Details for the file ecache-0.0.3.tar.gz
.
File metadata
- Download URL: ecache-0.0.3.tar.gz
- Upload date:
- Size: 11.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | f3f779e97972357db838728dafe20d2f10219bfe5e906c040b3a8f146600a773 |
|
MD5 | e76067315809aaf315e428ff72006532 |
|
BLAKE2b-256 | aa6fd45746098332ef7a22e83a44f6dbbf47c6afb35da90d8398f4918ede5f02 |