Skip to main content

Cache integration with sqlalchemy.

Project description

Run test

make unittest

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.1.tar.gz (1.9 kB view details)

Uploaded Source

File details

Details for the file ecache-0.0.1.tar.gz.

File metadata

  • Download URL: ecache-0.0.1.tar.gz
  • Upload date:
  • Size: 1.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No

File hashes

Hashes for ecache-0.0.1.tar.gz
Algorithm Hash digest
SHA256 66064dd5277dca4f36c83b07dba3a49fdb93a5494051a4286fa643881c52bb3e
MD5 2bf0f3c7d92db5ba9b57b61341983652
BLAKE2b-256 3b1adbcff8814765308c79d8fdac96674dda5e76d1df59724df3e4f9d1d26ebb

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page