mirror of
https://git.anonymousland.org/anonymousland/synapse.git
synced 2025-08-11 12:29:59 -04:00
Pull out the cache logic from the @cached wrapper into its own class we can reuse
This commit is contained in:
parent
b1022ed8b5
commit
0f86312c4c
2 changed files with 87 additions and 36 deletions
|
@ -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):
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue