When you initially opened this thread I thought you were suggesting a decorator that does the equivalent of a WeakValueDictionary. I guess you would need both in the library. 

We have both types of weak caches in our system (weak on value or weak on key), which we implemented. But the one that is weak on key (the function args) is evicted when any key element is GCed, rather than when the whole key is GCed. (It's tied to our system's memory management scheme in a very particular way.) So there are variations to think about with respect to that.

Maybe this is too complicated to be in the standard library?



On Friday, October 16, 2020, 09:49:04 AM GMT+1, Ram Rachum <ram@rachum.com> wrote:


I do that in a part of my code, and I need to handle the logic of first looking at that dictionary, and if it's not there, calculate it and store it in the dictionary. Is this what you meant? That's what I'm trying to avoid, doing all that manual work that a cache decorator is supposed to do for me in one line.