redcache.cache_manager Module

This module implements CacheManager class.

class redcache.cache_manager.CacheManager(key_base=u'cache', ttl=None, connection=None)[source]

This is the base class for cache managers.

key_base is used to prefix cache keys generated by this instance.

ttl is cache key TTL in seconds. If it is omitted (or None) then keys stored by this instance won’t expire.

connection allows binding the instance to an explicit Redis connection. If it is omitted global connection defined with redcache.connection.use_connection() will be used.

If no connection is defined then no caching will happen.

after_load(data, f_args=None, f_kwargs=None)[source]

Process and return data after loading it from Redis. f_args and f_kwargs contain positional and keywords args passed to decorated function.

Default implementation uses cPickle to unserialize data.

before_save(data, f_args=None, f_kwargs=None)[source]

Process and return data before saving it to Redis. f_args and f_kwargs contain positional and keywords args passed to decorated function.

Default implementation uses cPickle to unserialize data.

cache(f)[source]

Decorate f function to enable caching it.

If the function returns None then it won’t be cached.

connection[source]

Connection property.

key(f, args)[source]

Key generator for function f with positional arguments args.

Example key: key_base:func_name:arg1:arg2.

Instance and class methods

If the first argument of f is either self or cls it won’t be used while creating the key.

load(key, f_args=None, f_kwargs=None)[source]

Load data for key from Redis. f_args and f_kwargs contain positional and keywords args passed to decorated function.

Default implementation uses GET command.

save(key, data, f_args=None, f_kwargs=None)[source]

Save data into Redis key. f_args and f_kwargs contain positional and keywords args passed to decorated function.

Default implementation uses SET command.

class redcache.cache_manager.DefaultCacheManager(key_base=u'cache', ttl=None, connection=None)[source]

This is default cache manager for simple caching of generic functions.

Basically it’s equivalent to CacheManager with default settings.

cache(*args, **kwargs)[source]

Decorate f function to enable caching it.

Use ttl keyword arg to override default infinite TTL.

If the function returns None then it won’t be cached.

Previous topic

Welcome to RedCache documentation!

Next topic

redcache.connection Module

This Page