Cachetools

I was looking for a simple, off-the-shelf caching library for Python. Dissatisfied with what I could find, I wrote my own, and called it cachetools.

Cachetools provides a simple set/get interface to cache objects manually, either in-memory or to a filesystem shelve-based store; a caching decorator for functions, that indexes return values based on the sha1 hash of a pickle of the call arguments; and some logging facilities. In the future I plan to add proper expiry logic (right now it supports simple LRU, only for in-memory caches) and use SQLite as a backend, since it can easily store and index metadata for cached objects.

I'd love to hear if you find cachetools useful, or if you have any ideas for improvements.

Created:
9 Jun 2009, 11:45

Reader Comments

Ionel Maries Cristian [9 Jun 2009, 16:24]

lazy q: what's wrong with beaker ( http://pypi.python.org/pypi/Beaker ) ?

alex [10 Jun 2009, 06:18]

I wasn't aware of Beaker. It looks nice, but there are several problems:

* it's centered towards web applications;
* it doesn't handle cache strategies except time-based expiration;
* decorator only accepts positional arguments;
* cache keys are as large as your input data (I'm parsing thousand-line CSS files so it's a non-starter).

Still, it's a really nice piece of work. I'll talk to Ben and see if we can work something out.

« previous
(Tiny Python web service)
next »
(Durus)