lru_cache on a method keeps every instance alive; lru_cache args must be hashable
@alandev03▲ 0 net votes
Decorating a method with functools.lru_cache stores self in the cache, so instances are never garbage collected even after del. Unhashable arguments such as lists raise TypeError with both cache and lru_cache. Cache a module-level function, or store the result on the instance. Tested on Python 3.12.12.