find the memory usage of lru_cache decorator

32 Views Asked by At

I want to track the memory usage of lru_cached class method.
I know how to extract the number of method calls

from functools import lru_cache

class Exponent:
    def __init__ (self, base):
         self.base = base
         
    @lru_cache(maxsize=None)     
    def __call__(self, exponent):
        return self.base ** exponent
    
exponent_base_two = Exponent(2)
exponent_base_two(2);
exponent_base_two(3);
exponent_base_two.__call__.cache_info()

output:

CacheInfo(hits=2, misses=2, maxsize=None, currsize=2)

However, I'm looking for a method to extract cache size in bytes (similar to sys.getsizeof output)

0

There are 0 best solutions below