Is there a Python caching library?
Take a look at Beaker:
- Home Page
- Caching Documentation
- Good quick-start article about using Beaker with Django (but useful in any other apps too)
From Python 3.2 you can use the decorator @lru_cache from the functools library. It's a Least Recently Used cache, so there is no expiration time for the items in it, but as a fast hack it's very useful.
from functools import lru_cache
@lru_cache(maxsize=256)
def f(x):
return x*x
for x in range(20):
print f(x)
for x in range(20):
print f(x)