mirror of
https://github.com/python/cpython.git
synced 2025-08-31 05:58:33 +00:00
Support cache sizes.
This commit is contained in:
parent
a893927491
commit
0f56e90f05
2 changed files with 49 additions and 1 deletions
|
@ -144,7 +144,7 @@ def lfu_cache(maxsize=100):
|
|||
wrapper.misses += 1
|
||||
if len(cache) > maxsize:
|
||||
# purge the 10% least frequently used entries
|
||||
for key, _ in nsmallest(maxsize // 10,
|
||||
for key, _ in nsmallest(maxsize // 10 or 1,
|
||||
use_count.items(),
|
||||
key=itemgetter(1)):
|
||||
del cache[key], use_count[key]
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue