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.1.0.tar.gz
(11.5 kB
view details)
File details
Details for the file ecache-0.1.0.tar.gz
.
File metadata
- Download URL: ecache-0.1.0.tar.gz
- Upload date:
- Size: 11.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 1a730cd9fd4d60749ff78054747c53ed886dc120f79ebf783e82b41a44f1791e |
|
MD5 | d70004aa513b9f87a65cb13f499a75a8 |
|
BLAKE2b-256 | 6953f73d6bae598f611efa8f6f951ca21f5ae88c8a13150bdcf05b7f7544dcd7 |