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.

On Fri, Oct 16, 2020 at 11:45 AM Irit Katriel <iritkatriel@yahoo.com> wrote:
You can use a global WeakKeyDictionary keyed by the object to achieve the same without having anything on the object.


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

Did you mean like keeping a hidden attribute on the object with the result? Well, that'd require manually keeping track of these attributes for each method I'm caching. I do that sometimes, but it's verbose.