repoze/repoze.lru — Issue #3: Repeated pushing of same entry removes other cache entries
Author: snordhausen
Created: 2012-01-13 12:22:05+00:00
State: open

When the same cache entry is repeatedly put() into the cache, it will remove existing entries:

>>> c = LRUCache(3)
>>> c.put(1, 2)
>>> c.put(11, 22)
>>> c.put(111, 222)
>>> print c.data
{1: (0, 2), 11: (1, 22), 111: (2, 222)}

>>> c.put(1, 2)
>>> c.put(1, 2)
>>> c.put(1, 2)
>>> print c.data
{1: (2, 2)}

The reason is that put() does not check if the entry is already in the cache. Instead, every push operation inserts a new entry in self.clock, eventually replacing all other entries.