-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathexample.py
More file actions
37 lines (27 loc) · 927 Bytes
/
example.py
File metadata and controls
37 lines (27 loc) · 927 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
34
35
36
37
import asyncio
import json
import logging
from cache_house.backends import RedisFactory
from cache_house.cache import cache
from example1 import test_cache as tt
from example1 import test_cache_1 as tt1
log = logging.getLogger("cache_house.backends.redis_backend").setLevel(logging.DEBUG)
logging.basicConfig(level=logging.INFO)
RedisFactory.init(autodetect_cluster=True)
def custom_encoder(data):
return json.dumps(data)
def custom_decoder(data):
return json.loads(data)
@cache(expire=30, encoder=custom_encoder, decoder=custom_decoder, namespace="custom")
async def test_cache(a: int, b: int):
print("async cached")
return {"a": a, "b": b}
@cache(expire=30)
def test_cache_1(a: int, b: int):
print("cached")
return [a, b]
if __name__ == "__main__":
print(asyncio.run(test_cache(1, 2)))
print(test_cache_1(3, 4))
print(asyncio.run(test_cache(6, 2)))
print(test_cache_1(3, 0))