-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathtestStaticMethod.py
58 lines (46 loc) · 1.82 KB
/
testStaticMethod.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
#!/usr/bin/env python
from __future__ import (division, print_function)
import time
from memory_profiler import profile
class DataCache(object):
_duration = 300 # 5 minitues
_lastedActiveDataFromAgent = {}
@staticmethod
def setDuration(sec):
DataCache._duration = sec
@staticmethod
def getlatestJobData():
if (DataCache._lastedActiveDataFromAgent):
return DataCache._lastedActiveDataFromAgent["data"]
else:
return {}
@staticmethod
def setlatestJobData(jobData):
DataCache._lastedActiveDataFromAgent["time"] = int(time.time())
DataCache._lastedActiveDataFromAgent["data"] = jobData
@staticmethod
def islatestJobDataExpired():
if not DataCache._lastedActiveDataFromAgent:
return True
if (int(time.time()) - DataCache._lastedActiveDataFromAgent["time"]) > DataCache._duration:
return True
return False
@staticmethod
def summary():
print("DataCache type: {}, DataCache id: {}, DataCache.lastedActiveDataFromAgent id: {}".format(type(DataCache),
id(DataCache),
id(DataCache._lastedActiveDataFromAgent)))
@profile
def gatherActiveDataStats(inputData):
if DataCache.islatestJobDataExpired():
thisDict = {inputData: inputData * 5, "000": "blah"}
DataCache.setlatestJobData(thisDict)
print("DataCache is updated: {}".format(len(thisDict)))
else:
print("DataCache is up-to-date")
DataCache.summary()
if __name__ == "__main__":
DataCache.setDuration(15)
for i in range(5):
gatherActiveDataStats(i)
time.sleep(10)