repoze/repoze.lru — pull request #9 by snordhausen (2012-01-16 14:02:09+00:00)
Title: Fixes for issues #2-#8

Issue #2 (LRUCache will evict entries even though not full)
get() does not set self.hand any more, so no entries will be evicted before the cache is really full.

Issue #3 (Repeated pushing of same entry removes other cache entries)
LRUCache now checks if the key is already in the cache. If so, no other entries are evicted.

Issue #4 (LRUCache.clock wastes RAM)
self.clock was split up into two lists, thereby saving a dict for each cache entry

Issue #5 (LRUCache is not thread safe)
self.clear() now atomically resets self.clock_xxx, avoiding the index out of bounds errors when get() or put() were accessing self.clock. Additionally, reading self.hand in put() is now protected by a lock, preventing problems when many threads try to put() simultaneously and need to wait on another that holds the lock

Issue #6 (LRUCache.put() can take multiple seconds on large caches)
put() will now check at most 107 entries. This avoids applications from stalling and in the worst case, it will only evict <1% innocent victims. After that, it evicts those items that would have been evicted, anyway.

issue #7 (LRUCache should provide a way to remove items from the cache)
A new "invalidate()" method was added.