-
Notifications
You must be signed in to change notification settings - Fork 2
/
example.py
71 lines (54 loc) · 1.41 KB
/
example.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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
import time
from methodcache import cache, Store
st = Store(ttl=5)
class Car:
def __init__(self, serial_number, milage):
self.serial_number = serial_number
self.milage = milage
class CarManager:
@cache(store=st, category="car")
def get_cars(self):
time.sleep(2)
return [Car("JKaHO3hoHOe4GHOy4", 234214), Car("AJAHWho4HOI46HIOA4t", 34571)]
@cache(store=st, category="car:manufacturer", ttl=5)
def get_manufacturer(self):
time.sleep(3)
return ["BMW", "Opel", "Ford"]
class FruitManager:
@cache(store=st, category="fruit")
def get_fruits(self):
time.sleep(3)
return ["Apple", "Banana", "Pineapple"]
@cache(store=st, category="fruit:country")
def get_country(self):
time.sleep(3)
return ["Germany", "Ecuador", "Costa Rica"]
fruits = FruitManager()
print()
print("Without Cache")
print(fruits.get_fruits())
print(fruits.get_country())
print()
print("With Cache")
print("-"*10)
print(fruits.get_fruits())
print(fruits.get_country())
cars = CarManager()
print()
print("Without Cache")
print(cars.get_cars())
print(cars.get_manufacturer())
print()
print("With Cache")
print("-"*10)
print(cars.get_cars())
print(cars.get_manufacturer())
print()
print("With Expired TTL")
print("-"*10)
print(fruits.get_country())
print()
print("Get All Categorys")
print("-"*10)
print(st.get_all_categorys())
print(st.get_category("car"))