[Python-ideas] functools.lru_cache manual cache modification

Constantin Berhard constantin at exxxtremesys.lu
Mon Dec 1 17:34:16 CET 2014


I've written a tail call optimization lib for python3.
It works fine.

I use a custom return, which throws the next function arguments as an
exception and a decorator, which handles the exception.

One strength of the functools.lru_cache lies in caching results of calls
initiated by the function itself (i.e. recursive call results).

However because of the exception, the intermediate results from the tail
recursion don't end up in the cache, if my tail call optimization is
used together with lru_cache.

So I would like to be able to manually add argument-result pairs in the
cache. A manual lookup is not needed for my purpose, but I propose that
there should be methods to
1. add argument-result pairs to the cache
2. lookup if there is a result for given arguments
3. lookup the result for given arguments if it exists (exception thrown
4. invalidate specific cache entries (at the moment you can only
invalidate the cache as a whole through func.cache_clear())

What do you think?

Best Regards,

-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 819 bytes
Desc: OpenPGP digital signature
URL: <http://mail.python.org/pipermail/python-ideas/attachments/20141201/98c610c2/attachment.sig>

More information about the Python-ideas mailing list