Josh Rosenberg added the comment:

Manual adding to the cache seems of limited utility for the proposed recursion 
base case approach when your cache is actually operating in LRU mode (maxsize 
isn't None). You can inject your base cases all you want, but unless you wrap 
every call to the decorated function with another function that reinserts the 
base cases every time (and even that won't always work), you can't actually 
rely on the cache containing your base cases; they could be aged off at any 
time.

I've been bad and (for fun) used inspect to directly find the cache closure 
variable in an lru_cache wrapped function to inject base cases, but it only 
works if your cache is unbounded. Trying to make it actually work reliably in 
LRU mode would complicate matters. I suppose a collections.ChainMap (where one 
is the LRU map, and the other is an unbounded dictionary solely for injected 
entries) might work, but it also starts making the cache more expensive to use 
in general for a really limited use case.

----------
nosy: +josh.r

_______________________________________
Python tracker <rep...@bugs.python.org>
<http://bugs.python.org/issue23030>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to