/
backend_base.py
51 lines (44 loc) · 1.38 KB
/
backend_base.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
class Backend(object):
"""
Generic backend base class. Provides an interface to use the cache
with any backend
"""
def __init__(self, *args, **kwargs):
pass
def get_cache(self, key):
"""
Gets the given key from the cache backend
:param key: The cache key to get
:return: The value in the cache in the case of a cache hit,
otherwise None
"""
raise NotImplementedError()
def set_cache(self, key, value):
"""
Sets the given key/value pair in the cache backend
:param key: The cache key
:param value: The cache value
:return: Response from cache backend
"""
raise NotImplementedError()
def set_cache_and_expire(self, key, value, expiration):
"""
Sets the key/value pair in the cache backend with an expiration TTL
:param key: The cache key
:param value: The cache value
:param expiration: The time to live (ttl) in seconds
:return: Response from cache backend
"""
raise NotImplementedError()
def invalidate_key(self, key):
"""
Removes the key from the cache
:param key: The cache key
:return: Response from cache Backend
"""
raise NotImplementedError()
class BackendException(Exception):
"""
Cache backend exception
"""
pass