Add the concept of a data model cache, for caching of Namedtuple objects from the data model
Will be used to cache blobs, thus removing the need to hit the database in most blob requests
This commit is contained in:
parent
51e67ab7f5
commit
3c72e9878d
3 changed files with 72 additions and 0 deletions
16
data/cache/test/test_cache.py
vendored
Normal file
16
data/cache/test/test_cache.py
vendored
Normal file
|
@ -0,0 +1,16 @@
|
|||
import pytest
|
||||
|
||||
from data.cache import InMemoryDataModelCache, NoopDataModelCache
|
||||
from data.cache.cache_key import CacheKey
|
||||
|
||||
@pytest.mark.parametrize('cache_type', [
|
||||
(NoopDataModelCache),
|
||||
(InMemoryDataModelCache),
|
||||
])
|
||||
def test_caching(cache_type):
|
||||
key = CacheKey('foo', '60m')
|
||||
cache = cache_type()
|
||||
|
||||
# Perform two retrievals, and make sure both return.
|
||||
assert cache.retrieve(key, lambda: 1234) == 1234
|
||||
assert cache.retrieve(key, lambda: 1234) == 1234
|
Reference in a new issue