techu.libraries.caching

class techu.libraries.caching.Cache
Caching wrapper around Redis client.
Supports setting keys with WATCH as a CAS device along with expiration.
Also supports hash (dictionary) operations, handles invalidations and marks indexes as “dirty”.
delete(keys, expires=500)
Set key expiration at specified time in milliseconds.
Allows soft deletion by setting low expiration times.
If you set the expires parameter to 0 an immediate delete is performed (via the DELETE command)
dirty(index_id, action=u'')
Mark an index as “dirty” thus containing changes that
require cache entries concerning that index to be invalidated.
Specific actions will give finer control over invalidations in the future.
exists(key)

Check if a key exists in Redis

get(key, unserialize=True)

Return a value from Redis. Optionally transforms result ( when unserialize parameter is True - default ) through marshal.loads

hget(key)

Return all entries in a Redis hash structure as a dict

hset(key, inner_key, value, watch=False, expire=0.0, lock=None)

Set a hash entry in the structure specified by key and hash key inner_key

invalidate(index_id, version)

Invalidate cache entries

set(key, value, watch=False, expire=0.0, lock=None, keylist=None)
Store a key-value pair in Redis.
Optionally add WATCH for implementing CAS.
Supports also key-lock releasing in case cache locks are implemented (avoiding stampeding herd).
expire parameter is in seconds but of float type, multiplied by 10**3 and passed to PEXPIRE command
transaction()

Start a consistent & isolated operation (transaction)

version(index_id)

Index version

class techu.libraries.caching.FunctionCache(fn)
Creates a key with the function name and a hash of the arguments.
Parameter values (or keyword argument parameter values) must be serializable.
Used as a view decorator.

Previous topic

techu.libraries.authentication

Next topic

techu.libraries.generic

This Page