Python caching attributes in object with __slots__
I am trying to cache a computationally expensive property in a class defined with the __slots__ attribute. Any idea, how to store the cache for later use? Of course the usual way to store a dictionary in instance._cache would not work without __dict__ being defined. For several reasons i do not want to add a '_cache' string to __slots__. I was thinking whether this is one of the rare use cases for global. Any thoughts or examples on this matter?
0 upvotes
View original discussion ↗
Comments
Sign in or sign up to comment and upvote.
No comments yet.