This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author rhettinger
Recipients rhettinger, serhiy.storchaka
Date 2019-01-19.09:31:06
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1547890267.07.0.0655530638913.issue35780@roundup.psfhosted.org>
In-reply-to
Content
---------  Demonstration of one of the bugs ---------

# The currsize is initially equal to maxsize of 10
# Then we cause an orphan link in a full cache 
# The currsize drops to 9 and never recovers the full size of 10

from functools import lru_cache

once = True

@lru_cache(maxsize=10)
def f(x):
    global once
    rv = f'.{x}.'
    if x == 20 and once:
        once = False
        print('Calling again', f(x))
    return rv

for x in range(15):
    f(x)

print(f.cache_info())
print(f(20))
print(f.cache_info())
print(f(21))
print(f.cache_info())


------ Output --------
CacheInfo(hits=0, misses=15, maxsize=10, currsize=10)
Calling again .20.
.20.
CacheInfo(hits=0, misses=17, maxsize=10, currsize=9)
.21.
CacheInfo(hits=0, misses=18, maxsize=10, currsize=9)
History
Date User Action Args
2019-01-19 09:31:08rhettingersetrecipients: + rhettinger, serhiy.storchaka
2019-01-19 09:31:07rhettingersetmessageid: <1547890267.07.0.0655530638913.issue35780@roundup.psfhosted.org>
2019-01-19 09:31:07rhettingerlinkissue35780 messages
2019-01-19 09:31:07rhettingercreate