I have a class with a method that is annotated with the lru_cache annotation:
CACHE_SIZE=16384
class MyClass:
[...]
@lru_cache(maxsize=CACHE_SIZE)
def _my_method(self, texts: Tuple[str]):
<some heavy text processing>
def cache_info(self):
return self._my_method.cache_info()
After running for a while, I look at the cache statistics through the cache_info() method:
c = MyClass()
[...]
c.cache_info()
{
"hits":9348,
"misses":4312,
"maxsize":16384,
"currsize":2588
}
My question is: how can currsize be smaller than misses AND smaller than maxsize?
My understanding was: for each miss, the result is added to the cache, hence increasing the current size. Only when the current size has reached the maximum size, cached results are removed. Since the maximum size is not reached here yet, each miss should be cached, so currsize should equal misses at this point.
However, that does not seem to be the way this works.