I'm looking for a Python caching library but can't find anything so far. I need a simple dict
-like interface where I can set keys and their expiration and get them back cached. Sort of something like:
cache.get(myfunction, duration=300)
which will give me the item from the cache if it exists or call the function and store it if it doesn't or has expired. Does anyone know something like this?
keyring is the best python caching library. You can use
No one has mentioned shelve yet. https://docs.python.org/2/library/shelve.html
It isn't memcached, but looks much simpler and might fit your need.
Look at gocept.cache on pypi, manage timeout.
From Python 3.2 you can use the decorator @lru_cache from the functools library. It's a Last Recently Used cache, so there is no expiration time for the items in it, but as a fast hack it's very useful.
Try redis, it is one of the cleanest and easiest solutions for applications to share data in a atomic way or if you have got some web server platform. Its very easy to setup, you will need a python redis client http://pypi.python.org/pypi/redis
Look at bda.cache http://pypi.python.org/pypi/bda.cache - uses ZCA and is tested with zope and bfg.