redis-simple-cache 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.
Project description
Warning: This is not a major bug, since the decorators doesn't use the flush method of SimpleCache,
but in this 0.0.2 release the flush method doesn't work properly.
The method flushes the redis keys set used by SimpleCache, but doesn't flush the real keys on redis-server.
If you want to use the flush method, please use the 0.0.3 or above version: http://pypi.python.org/pypi/redis-simple-cache/0.0.3
# redis-simple-cache
redis-simple-cache 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:
-------------
redis 2.6.2
redis-py 2.7.1 (see requirements.txt file)
Installation:
-------------
pip install redis-simple-cache
or
git clone git://github.com/fjsj/redis-simple-cache.git
cd redis-simple-cache
python setup.py install
Usage:
------
from redis_cache import cache_it
@cache_it(limit=1000, expire=60 * 60 * 24)
def fib(n):
if n == 0:
return 0
elif n == 1:
return 1
else:
return fib(n-1) + fib(n-2)
`limit` is the maximum number of keys, `expire` is the expire time in seconds.
It is always recommended to specify a expire time, since by default redis-server will only remove keys with an expire time set. But if you wish your keys to never expire, set `expire` to `None`.
**Note that function arguments and result must be pickleable, since cache_it uses the pickle module.**
It is also possible to use redis-simple-cache as a object-oriented cache:
>> from redis_cache import SimpleCache
>> c = SimpleCache(10) # cache that has a maximum limit of 10 keys
>> c.store("foo", "bar")
>> c.get("foo")
'bar'
>> "foo" in c # efficient membership test, time-complexity O(1)
True
>> len(c) # efficient cardinality calculation, time-complexity O(1)
1
>> c.keys() # returns all keys, time-complexity O(N) with N being the cache c cardinality
set(['foo'])
>> c.flush() # flushes the cache, time-complexity O(N) with N being the cache c cardinality
>> "foo" in c
False
>> len(c)
0
Check out more examples in the tests.py file.
AUTHOR: Vivek Narayanan
FORKED AND IMPROVED BY: Flávio Juvenal
LICENSE: BSD
but in this 0.0.2 release the flush method doesn't work properly.
The method flushes the redis keys set used by SimpleCache, but doesn't flush the real keys on redis-server.
If you want to use the flush method, please use the 0.0.3 or above version: http://pypi.python.org/pypi/redis-simple-cache/0.0.3
# redis-simple-cache
redis-simple-cache 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:
-------------
redis 2.6.2
redis-py 2.7.1 (see requirements.txt file)
Installation:
-------------
pip install redis-simple-cache
or
git clone git://github.com/fjsj/redis-simple-cache.git
cd redis-simple-cache
python setup.py install
Usage:
------
from redis_cache import cache_it
@cache_it(limit=1000, expire=60 * 60 * 24)
def fib(n):
if n == 0:
return 0
elif n == 1:
return 1
else:
return fib(n-1) + fib(n-2)
`limit` is the maximum number of keys, `expire` is the expire time in seconds.
It is always recommended to specify a expire time, since by default redis-server will only remove keys with an expire time set. But if you wish your keys to never expire, set `expire` to `None`.
**Note that function arguments and result must be pickleable, since cache_it uses the pickle module.**
It is also possible to use redis-simple-cache as a object-oriented cache:
>> from redis_cache import SimpleCache
>> c = SimpleCache(10) # cache that has a maximum limit of 10 keys
>> c.store("foo", "bar")
>> c.get("foo")
'bar'
>> "foo" in c # efficient membership test, time-complexity O(1)
True
>> len(c) # efficient cardinality calculation, time-complexity O(1)
1
>> c.keys() # returns all keys, time-complexity O(N) with N being the cache c cardinality
set(['foo'])
>> c.flush() # flushes the cache, time-complexity O(N) with N being the cache c cardinality
>> "foo" in c
False
>> len(c)
0
Check out more examples in the tests.py file.
AUTHOR: Vivek Narayanan
FORKED AND IMPROVED BY: Flávio Juvenal
LICENSE: BSD
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
Built Distribution
Close
Hashes for redis_simple_cache-0.0.2-py2.7.egg
Algorithm | Hash digest | |
---|---|---|
SHA256 | 5ecd7659cb07e537bf7a8673cc5063d924962254e258cc6fd216d61b20f77d63 |
|
MD5 | 7cf0fe0f087fec0e072b43a9145f52f3 |
|
BLAKE2b-256 | eba7cb6c688831033ec66edb2b536845c3c5c52a3b580b380afd3206d406a69f |