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
# 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)
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 number of keys in the database
["SimpleCache::foo"]
>> c.flush() # flushes the cache, time-complexity O(N) with N being the number of keys in the database
>> "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
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)
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 number of keys in the database
["SimpleCache::foo"]
>> c.flush() # flushes the cache, time-complexity O(N) with N being the number of keys in the database
>> "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
File details
Details for the file redis-simple-cache-0.0.1.tar.gz
.
File metadata
- Download URL: redis-simple-cache-0.0.1.tar.gz
- Upload date:
- Size: 4.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 2cdfd5379ee4a1afb12523c5ad538008561d3d3a1deb63af67c25a2c71d495e0 |
|
MD5 | 780703dc9432d6999b46b2c969f63903 |
|
BLAKE2b-256 | e60a85d3106585d47d90d7d3e804c86e98c5efa7d80d218d5c9452121296b76d |
Provenance
File details
Details for the file redis_simple_cache-0.0.1-py2.7.egg
.
File metadata
- Download URL: redis_simple_cache-0.0.1-py2.7.egg
- Upload date:
- Size: 6.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | bfb72522f0e5b6845a9056128df8f114e464410ddc934490f36dfa2293a75fca |
|
MD5 | bab10b18c66dcd66359dcfa48820cb37 |
|
BLAKE2b-256 | c25163b7e3cba29dafe3089378029384bb7ce9da6b84e61ff2a26f4c3d1f77b1 |