I’m using a functools.lru_cache to serve temp file paths given certain input*. However in case the path no longer exists, I would like to remove/replace the single corresponding key. The cache_clear() method would be overkill and cache_info() do not appear to help. Thanks for your help! * The method being cached streams a fileobj from S3 to a local temp
Tag: lru
Python functools lru_cache with instance methods: release object
How can I use functools.lru_cache inside classes without leaking memory? In the following minimal example the foo instance won’t be released although going out of scope and having no referrer (other than the lru_cache). But foo and hence foo.big (a BigClass) are still alive That means that Foo/BigClass instances are still residing in memory. Even deleting Foo (del Foo) will