New submission from Marek Otahal:
I'd like to use @lru_cache in a library. The problem is I can't know the
optimal values for 'maxsize', I need to set them at runtime.
I came with 2 possibilities:
1/ set cache's size from a hardcoded argument of the decorated method:
@lru_cache
def foo_long
Marek Otahal added the comment:
Hope this example is not too confusing, it's a patch to my code and lru_cache
(backport for python 2.7 from ActiveState)
It implements both approaches as highlighted above, and in the test both of
them are used (that does not make much sense, normally one would
Marek Otahal added the comment:
Hi David,
> How is (1) different from:
@lru_cache(maxsize=1000)
def foo_long(self, arg1...)
As I mentioned, for use in a library that is called by end-users. They can call
functions and modify params, but do not edit the code. It's up to me (lib d
Marek Otahal added the comment:
EDIT:
> i.foo_long(1337)
ofc, this should be:
i.foo_long('hi', cacheSize=1337)
or for (2):
class MyLib():
def __init__(arg1, arg2):
self._cacheSize = someComputation(arg1, arg2) # returns a number
@lru_cache
def foo_long(self, arg1, **k