[issue24969] functools.lru_cache: a way to set decorator arguments at runtime

2015-09-05 Thread Raymond Hettinger
Raymond Hettinger added the comment: Sorry, I'm going to reject this one. This option was considered during the design of the LRU cache and not included because it complicated the design, because the use cases were not common (the norm is set and forget), and because the __wrapped__ attribute

[issue24969] functools.lru_cache: a way to set decorator arguments at runtime

2015-09-04 Thread Terry J. Reedy
Changes by Terry J. Reedy : -- stage: -> test needed ___ Python tracker ___ ___ Python-bugs-list mailing list Unsubscribe: https://m

[issue24969] functools.lru_cache: a way to set decorator arguments at runtime

2015-08-31 Thread Raymond Hettinger
Raymond Hettinger added the comment: > The problem is I can't know the optimal values for 'maxsize', > I need to set them at runtime. The easiest way to go is to wait to start caching until you know the cache size you want: def foo(a, b, c): pass size = get_user_request()

[issue24969] functools.lru_cache: a way to set decorator arguments at runtime

2015-08-31 Thread Raymond Hettinger
Changes by Raymond Hettinger : -- assignee: -> rhettinger nosy: +rhettinger versions: +Python 3.6 ___ Python tracker ___ ___ Python-b

[issue24969] functools.lru_cache: a way to set decorator arguments at runtime

2015-08-31 Thread R. David Murray
R. David Murray added the comment: There is no patch/example attached. It seems like what you really want is an API on lru_cache for updating the cache size. What I'm saying is that the cache size can be passed in on the MyLib call, and the decorator/function constructed as part of MyLib's i

[issue24969] functools.lru_cache: a way to set decorator arguments at runtime

2015-08-31 Thread Marek Otahal
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, **kwds): pas

[issue24969] functools.lru_cache: a way to set decorator arguments at runtime

2015-08-31 Thread Marek Otahal
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 devs) to

[issue24969] functools.lru_cache: a way to set decorator arguments at runtime

2015-08-31 Thread Marek Otahal
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

[issue24969] functools.lru_cache: a way to set decorator arguments at runtime

2015-08-31 Thread R. David Murray
R. David Murray added the comment: How is (1) different from: @lru_cache(maxsize=1000) def foo_long(self, arg1...) As for computing it at runtime: if you need to compute it, you can compute it and *then* define the decorator wrapped function. -- nosy: +r.david.murray ___

[issue24969] functools.lru_cache: a way to set decorator arguments at runtime

2015-08-31 Thread Marek Otahal
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(