This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author Marek Otahal
Recipients Marek Otahal
Date 2015-08-31.15:47:20
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1441036040.75.0.88592797115.issue24969@psf.upfronthosting.co.za>
In-reply-to
Content
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
History
Date User Action Args
2015-08-31 15:47:20Marek Otahalsetrecipients: + Marek Otahal
2015-08-31 15:47:20Marek Otahalsetmessageid: <1441036040.75.0.88592797115.issue24969@psf.upfronthosting.co.za>
2015-08-31 15:47:20Marek Otahallinkissue24969 messages
2015-08-31 15:47:20Marek Otahalcreate