Is there a Python caching library? Is there a Python caching library? python python

Is there a Python caching library?


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.

from functools import lru_cache@lru_cache(maxsize=256)def f(x):  return x*xfor x in range(20):  print f(x)for x in range(20):  print f(x)


You might also take a look at the Memoize decorator. You could probably get it to do what you want without too much modification.