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(self, arg1, ..., **kwds): pass # use foo_long('hi', cacheSize = 1000) This approach allows the users to customize cache size for their problem. 2/ from function's **kwds retrieve a name (string) of an instance member of the class which will hold the cache's size value. This is not as clean as 1/, but offers greated functionality for the use in a library sw: we can compute desired cache size from internal values of the unstance, and the use of cache can be totally transparent to the end user: @lru_cache def foo_long(self, arg1, .. , **kwds) #use foo_long('hi', cacheSizeRef='_cacheSize') What do you think about the proposal? best regards, Mark ---------- messages: 249406 nosy: Marek Otahal priority: normal severity: normal status: open title: functools.lru_cache: a way to set decorator arguments at runtime type: enhancement _______________________________________ Python tracker <rep...@bugs.python.org> <http://bugs.python.org/issue24969> _______________________________________ _______________________________________________ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com