This is a pre-production deployment of Warehouse, however changes made here WILL affect the production instance of PyPI.
Latest Version Dependencies status unknown Test status unknown Test coverage unknown
Project Description

RedCache is a lightweight and extensible caching framework for Python applications. It uses Redis as its storage backend.

Quickstart

Suppose we have a function that loads data from a remote source:

def load_something_from_somewhere():
    # Load the data...
    return data

Now let’s use it in a Flask view:

@app.route('/something/')
def get_something():
    data = load_something_from_somewhere()
    # Do something with the data...
    return jsonify(data=data)

The problem here is that the view will wait until the data is fetched. If the view is called often it’ll generate significant traffic between our server and the remote source. This isn’t pretty.

What if we cached the loaded data for some time and refresh it only when the cache expires? That would be pretty.

There are many caching solutions, e.g. Beaker. RedCache is similar to (and inspired by) Beaker but provides only one storage backend - Redis.

So, how do you cache load_something_from_somewhere using Redis and RedCache?

First setup Redis connection before starting the app:

from redcache import use_connection
use_connection()

Then make the function cached:

from redcache import default_cache

@default_cache.cache(ttl=5)
def load_something_from_somewhere():
    # Load the data...
    return data

Next time load_something_from_somewhere is called RedCache will try to load its last return value from Redis. If it’s not found then the function will be executed and its return value stored in Redis for 5 seconds.

redcache.default_cache is an instance of redcache.cache_manager.DefaultCacheManager which gives convenient access to caching mechanism which uses cPickle behind the scenes. By default the keys will be stored infinitely. Use ttl keyword argument in the decorator to define different TTL.

Extending and advanced use

RedCache can be easily extended to utilize Redis’ datatypes and features.

By overriding redcache.cache_manager.CacheManager.after_load and redcache.cache_manager.CacheManager.before_save you can perform additional operations on data. This way you can e.g. store JSON strings instead of pickled objects.

By overriding redcache.cache_manager.CacheManager.load and redcache.cache_manager.CacheManager.save you can change the way data is loaded and saved. This way you can e.g. store lists of individual objects and retrieve them according to pagination options.

Consult examples to see how to integrate RedCache with SQLAlchemy and to see how to use JSON instead of cPickle.

Author, credits and license

RedCache is developed by BTHLabs.

RedCache is licensed under BSD License. See LICENSE for more details.

This project uses Redis connection management code from RQ.

This project uses context-local objects code from Werkzeug.

Source code

Source code is available from project repository on GitHub.

Release History

Release History

0.3

This version

History Node

TODO: Figure out how to actually get changelog content.

Changelog content for this version goes here.

Donec et mollis dolor. Praesent et diam eget libero egestas mattis sit amet vitae augue. Nam tincidunt congue enim, ut porta lorem lacinia consectetur. Donec ut libero sed arcu vehicula ultricies a non tortor. Lorem ipsum dolor sit amet, consectetur adipiscing elit.

Show More

0.2

History Node

TODO: Figure out how to actually get changelog content.

Changelog content for this version goes here.

Donec et mollis dolor. Praesent et diam eget libero egestas mattis sit amet vitae augue. Nam tincidunt congue enim, ut porta lorem lacinia consectetur. Donec ut libero sed arcu vehicula ultricies a non tortor. Lorem ipsum dolor sit amet, consectetur adipiscing elit.

Show More

0.1

History Node

TODO: Figure out how to actually get changelog content.

Changelog content for this version goes here.

Donec et mollis dolor. Praesent et diam eget libero egestas mattis sit amet vitae augue. Nam tincidunt congue enim, ut porta lorem lacinia consectetur. Donec ut libero sed arcu vehicula ultricies a non tortor. Lorem ipsum dolor sit amet, consectetur adipiscing elit.

Show More

Download Files

Download Files

TODO: Brief introduction on what you do with files - including link to relevant help section.

File Name & Checksum SHA256 Checksum Help Version File Type Upload Date
RedCache-0.3.tar.gz (19.5 kB) Copy SHA256 Checksum SHA256 Source Oct 8, 2013

Supported By

WebFaction WebFaction Technical Writing Elastic Elastic Search Pingdom Pingdom Monitoring Dyn Dyn DNS Sentry Sentry Error Logging CloudAMQP CloudAMQP RabbitMQ Heroku Heroku PaaS Kabu Creative Kabu Creative UX & Design Fastly Fastly CDN DigiCert DigiCert EV Certificate Rackspace Rackspace Cloud Servers DreamHost DreamHost Log Hosting