Pull out the cache logic from the @cached wrapper into its own class we can reuse

This commit is contained in:
Paul "LeoNerd" Evans 2015-03-20 18:13:49 +00:00
parent b1022ed8b5
commit 0f86312c4c
2 changed files with 87 additions and 36 deletions

View file

@ -17,7 +17,39 @@
from tests import unittest
from twisted.internet import defer
from synapse.storage._base import cached
from synapse.storage._base import Cache, cached
class CacheTestCase(unittest.TestCase):
def setUp(self):
self.cache = Cache("test")
def test_empty(self):
failed = False
try:
self.cache.get("foo")
except KeyError:
failed = True
self.assertTrue(failed)
def test_hit(self):
self.cache.prefill("foo", 123)
self.assertEquals(self.cache.get("foo"), 123)
def test_invalidate(self):
self.cache.prefill("foo", 123)
self.cache.invalidate("foo")
failed = False
try:
self.cache.get("foo")
except KeyError:
failed = True
self.assertTrue(failed)
class CacheDecoratorTestCase(unittest.TestCase):