Using the LRU Cache decorator found here: http://code.activestate.com/recipes/578078-py26-and-py30-backport-of-python-33s-lru-cache/
from lru_cache import lr
These days, methodtools will work
methodtools
from methodtools import lru_cache class Test: @lru_cache(maxsize=16) def cached_method(self, x): return x + 5
You need to install methodtools
pip install methodtools
If you are still using py2, then functools32 also is required
pip install functools32