I want to implement a basic cache in Python.
It's like this. I've 2 files named :- cache.py , main.py.
In my cache.py, I want to build a list every 24 hours. So, i run a cronjob cache.py every 24 hours which returns me the latest list.
cache.py
def get_hubcode_threshold_time():
global threshold_time
hub_alarm_obj = HubAlarm.objects.all().values('time').distinct()
for obj in hub_alarm_obj:
threshold_time.append(obj.time)
if __name__ == "__main__":
get_hubcode_threshold_time()
print threshold_time
I run main.py every minute (another cronjob). I want to print threshold_time from the cache.
main.py
import cache
print threshold_time
throws an error saying
NameError: global name 'threshold_time' is not defined
How do I implement a basic cache in Python:?