Skip to main content
# 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 to get the latest version

git clone git://github.com/vivekn/redis-simple-cache.git
cd redis-simple-cache
python setup.py install

Usage:
------

from redis_cache import cache_it_json

@cache_it_json(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 in a event of full memory. 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 test_rediscache.py file.

Advanced:
---------
Advanced users can customize the decorators even more by passing a SimpleCache object. For example:

my_cache = SimpleCache(limit=100, expire=60 * 60, hashkeys=True, host='localhost', port=6379, db=1, namespace='Fibonacci')
@cache_it(cache=my_cache)
def fib(n):
# ...

`hashkeys` parameter makes the SimpleCache to store keys in md5 hash. It is `True` by default in decorators, but `False` by default in a new SimpleCache object.
`host`, `port` and `db` are the same redis config params used in StrictRedis class of redis-py.
By default, the `namespace` is the name of the module from which the decorated function is called, but it can be overridden with the `namespace` parameter.

AUTHOR: Vivek Narayanan

CONTRIBUTORS:

Flávio Juvenal

Sam Zaydel

David Ng

DJ Gilcrease

Johannes Maximilian Toball

Robert Marshall

Ben Hayden

LICENSE: BSD

Metadata

Release files for redis-simple-cache 0.0.8

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for redis-simple-cache 0.0.8
File Size Uploaded Provenance Actions
redis-simple-cache-0.0.8.tar.gz 9.7 kB Without provenance Details for redis-simple-cache-0.0.8.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for redis-simple-cache 0.0.8
File Interpreter ABI Platform Actions
redis-simple-cache-0.0.8.macosx-10.10-intel.tar.gz Details for redis-simple-cache-0.0.8.macosx-10.10-intel.tar.gz

Total release size: 25.0 kB

Release files / redis-simple-cache-0.0.8.tar.gz

Download URL redis-simple-cache-0.0.8.tar.gz
Size 9.7 kB
Tags Source
SHA-256 checksum
How to use checksums
e81ce18db84d8000ed0be9295b632fb70f305d2a81a14390544fca8a72155cc7
BLAKE2b-256 checksum
How to use checksums
0c68e92ec001d1c539a0627f9c44f38c1034a624e90224be11e7a9c18da38d1c
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Release files / redis-simple-cache-0.0.8.macosx-10.10-intel.tar.gz

Download URL redis-simple-cache-0.0.8.macosx-10.10-intel.tar.gz
Size 15.3 kB
Tags Source
SHA-256 checksum
How to use checksums
da3840787e997b78a0f64da16e6a7f658dd6a24d9757cbd3049500d672685d47
BLAKE2b-256 checksum
How to use checksums
14b3a0206b5f0e5f9b8469df71d350d2b965b6d47b4e54af3b57e475d5c963da
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Security for redis-simple-cache 0.0.8

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page