File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -291,19 +291,23 @@ def wrapper(*args, **kwds):
291291 # computed result and update the count of misses.
292292 pass
293293 elif full :
294- # use root to store the new key and result
295- root [ KEY ] = key
296- root [ RESULT ] = result
297- cache [ key ] = root
294+ # use the old root to store the new key and result
295+ oldroot = root
296+ oldroot [ KEY ] = key
297+ oldroot [ RESULT ] = result
298298 # empty the oldest link and make it the new root
299- root = root [NEXT ]
300- del cache [root [KEY ]]
299+ root = oldroot [NEXT ]
300+ oldkey = root [KEY ]
301+ oldvalue = root [RESULT ]
301302 root [KEY ] = root [RESULT ] = None
303+ # now update the cache dictionary for the new links
304+ del cache [oldkey ]
305+ cache [key ] = oldroot
302306 else :
303307 # put result in a new link at the front of the queue
304308 last = root [PREV ]
305309 link = [last , root , key , result ]
306- cache [ key ] = last [ NEXT ] = root [ PREV ] = link
310+ last [ NEXT ] = root [ PREV ] = cache [ key ] = link
307311 full = (len (cache ) == maxsize )
308312 misses += 1
309313 return result
You can’t perform that action at this time.
0 commit comments