-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathjson_example.py
More file actions
33 lines (20 loc) · 776 Bytes
/
Copy pathjson_example.py
File metadata and controls
33 lines (20 loc) · 776 Bytes
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
"""Example of using JSON to serialize cached objects."""
import json
from cache_manager import CacheManager, get_current_connection, use_connection
class JsonCacheManager(CacheManager):
def before_save(self, data, **kwargs):
return json.dumps(data)
def after_load(self, data, **kwargs):
return json.loads(data)
json_cache_manager = JsonCacheManager()
def test_json_cache_manager():
@json_cache_manager.cache
def cached(spam, eggs):
return {'spam': spam, 'eggs': eggs}
result = cached('spam', 'eggs')
connection = get_current_connection()
print connection.get('cache:cached:spam:eggs')
connection.delete('cache:cached:spam:eggs')
if __name__ == '__main__':
use_connection()
test_json_cache_manager()