Skip to content

Commit e2232f1

Browse files
committed
Add comments to __call__ method MultiHitLRUCache for clarity
1 parent 2c24cbc commit e2232f1

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

Doc/library/collections.rst

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1252,13 +1252,14 @@ variants of :func:`functools.lru_cache`:
12521252
self.cache.move_to_end(args)
12531253
return self.cache[args]
12541254
result = self.func(*args)
1255-
self.requests[args] = self.requests.get(args, 0) + 1
1255+
self.requests[args] = self.requests.get(args, 0) + 1 # increment existing value by 1 if seen before, otherwise set to 1
12561256
if self.requests[args] <= self.cache_after:
12571257
self.requests.move_to_end(args)
12581258
if len(self.requests) > self.maxrequests:
12591259
self.requests.popitem(last=False)
12601260
else:
1261-
self.requests.pop(args)
1261+
# entry has been seen more than cache_after times
1262+
self.requests.pop(args) # no longer need to keep track of how many times this entry has been seen
12621263
self.cache[args] = result
12631264
if len(self.cache) > self.maxsize:
12641265
self.cache.popitem(last=False)

0 commit comments

Comments
 (0)