I'm using the decorator
@Carlos Pinzón, posted as an answer as you requested: functools.lru_cache() is designed to work with arbitrary positional and keyword arguments, and possibly a maximum cache size. If you don't need those features, it isn't too difficult to roll your own cache (aka memoize) decorator. The cache is just a dictionary, so you can provide a function to save it to disk as a pickle (or json if you want to be able to look at it) and reload it later. The lru_cache sourcecode is also available; modify it to suit your needs.