classification
Title: allow to cache_clear(some_key) in lru_cache
Type: enhancement Stage:
Components: Library (Lib) Versions: Python 3.7
process
Status: closed Resolution: rejected
Dependencies: Superseder:
Assigned To: rhettinger Nosy List: Sébastien de Menten, ncoghlan, rhettinger, serhiy.storchaka
Priority: normal Keywords:

Created on 2016-09-16 07:17 by Sébastien de Menten, last changed 2016-09-17 18:24 by rhettinger. This issue is now closed.

Messages (5)
msg276680 - (view) Author: Sébastien de Menten (Sébastien de Menten) Date: 2016-09-16 07:17
It would be useful to be able to clear a single item in the cache of a lru_cache decorated function.

Currently with:

@lru_cache
def foo(i):
  return i*2
foo(1)    # -> add 1 as key in the cache
foo(2)    # -> add 2 as key in the cache
foo.clear_cache() # -> this clears the whole cache
foo.clear_cache(1) # -> this would clear the cache entry for 1
msg276685 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2016-09-16 08:59
Method with name clear() usually removes all content. It would be better to use different name: remove() or invalidate() (is there a precedence in other caches?).
msg276800 - (view) Author: Nick Coghlan (ncoghlan) * (Python committer) Date: 2016-09-17 15:21
I'm wary of adding too much complexity to the standard cache API, especially when it's something that isn't found in http://boltons.readthedocs.io/en/latest/cacheutils.html either.

I do think it could be a good idea to provide some "See Also" links to alternate caching libraries for folks that are looking for features that standard implementation doesn't provide.
msg276805 - (view) Author: Raymond Hettinger (rhettinger) * (Python committer) Date: 2016-09-17 16:59
I concur with Nick that the API needs to be relatively simple.

The availability of a fast ordered dictionary now makes it very easy for people to roll their own customizations.
msg276812 - (view) Author: Raymond Hettinger (rhettinger) * (Python committer) Date: 2016-09-17 18:24
FYI, here is a starting point for rolling your own variants.  The OrderedDict makes this effortless.  http://pastebin.com/LDwMwtp8
History
Date User Action Args
2016-09-17 18:24:17rhettingersetmessages: + msg276812
2016-09-17 16:59:30rhettingersetstatus: open -> closed
resolution: rejected
messages: + msg276805
2016-09-17 16:58:16rhettingersetassignee: rhettinger
2016-09-17 15:21:53ncoghlansetmessages: + msg276800
2016-09-16 08:59:32serhiy.storchakasetnosy: + rhettinger, ncoghlan, serhiy.storchaka

messages: + msg276685
versions: + Python 3.7
2016-09-16 07:17:46Sébastien de Mentencreate