-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcache_admin.py
45 lines (34 loc) · 1.02 KB
/
cache_admin.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
import json
import os
class cache_admin:
def __init__(self, key=None, value=None):
self.key = key
self.value = value
def cache_utilization(self):
with open('cache.json') as cj:
data = json.load(cj)
cj.close()
return data
def cache_add(self):
with open('cache.json','r+') as cj:
data = json.load(cj)
cj.close()
data[self.key]= self.value
with open('cache.json','w') as cj:
json.dump(data, cj)
cj.close()
def cache_write(self):
with open("cache.json", "w") as cj:
json.dump({self.key:self.value}, cj)
def del_cache(self):
os.remove('cache.json')
def cache_workflow(self):
try:
data = self.cache_utilization()
if self.key in data:
print(data[self.key])
else:
pass
self.cache_add()
except:
self.cache_write()