mobacache

mobacache is a pythonic interface for creating a cache over redis or other provider. It provides simple decorators that can be added to any function to cache its return values.

MIT License

Downloads
221
Stars
9
Committers
2

mobacache Build Status

mobacache is a pythonic interface for creating a cache over redis. It provides simple decorators that can be added to any function to cache its return values.

Requirements:

Python 2.7+

Installation

pip install moba-cache

or to get the latest version

git clone https://github.com/redrush85/mobacache.git
cd mobacache
python setup.py install

Usage

Setup

from mobacache import CacheBuilder
import redis

redis_conn = redis.StrictRedis()
cb = CacheBuilder(redis_conn)

Cache

@cb.cache(ttl=10)
def my_method(a=1, b=2, c=0):
    return a + b + c

Advance cache

@cb.advance_cache(key_format="{a}:{b}:var_c={c}", ttl=10)
def my_method(a=0, b=0, c=0):
    return a + b + c
    
my_method(1, 2, 3)
data = cb.get("1:2:var_c=3")
print(data) # 6

Contributors

  • Alexander Kuts
  • Roman Gorin

Tests

python -m unittest