mirror of
https://git.anonymousland.org/anonymousland/synapse.git
synced 2025-05-02 11:26:09 -04:00
Allow a choice of LRU behaviour for Cache() by using LruCache() or OrderedDict()
This commit is contained in:
parent
d6b3ea75d4
commit
9ba6487b3f
2 changed files with 34 additions and 8 deletions
|
@ -69,6 +69,28 @@ class CacheTestCase(unittest.TestCase):
|
|||
cache.get(2)
|
||||
cache.get(3)
|
||||
|
||||
def test_eviction_lru(self):
|
||||
cache = Cache("test", max_entries=2, lru=True)
|
||||
|
||||
cache.prefill(1, "one")
|
||||
cache.prefill(2, "two")
|
||||
|
||||
# Now access 1 again, thus causing 2 to be least-recently used
|
||||
cache.get(1)
|
||||
|
||||
cache.prefill(3, "three")
|
||||
|
||||
failed = False
|
||||
try:
|
||||
cache.get(2)
|
||||
except KeyError:
|
||||
failed = True
|
||||
|
||||
self.assertTrue(failed)
|
||||
|
||||
cache.get(1)
|
||||
cache.get(3)
|
||||
|
||||
|
||||
class CacheDecoratorTestCase(unittest.TestCase):
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue