Message249406
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 |
|
Date |
User |
Action |
Args |
2015-08-31 15:47:20 | Marek Otahal | set | recipients:
+ Marek Otahal |
2015-08-31 15:47:20 | Marek Otahal | set | messageid: <1441036040.75.0.88592797115.issue24969@psf.upfronthosting.co.za> |
2015-08-31 15:47:20 | Marek Otahal | link | issue24969 messages |
2015-08-31 15:47:20 | Marek Otahal | create | |
|