From 9b39bfee94ba0dffe3ec0f8ba1be95cc9d3e190a Mon Sep 17 00:00:00 2001 From: Bob Mottram Date: Tue, 20 Aug 2019 10:50:27 +0100 Subject: [PATCH] Check if cache entry was loaded --- cache.py | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/cache.py b/cache.py index a127b2725..75c852a32 100644 --- a/cache.py +++ b/cache.py @@ -35,17 +35,20 @@ def getPersonFromCache(baseDir: str,personUrl: str,personCache: {}) -> {}: """Get an actor from the cache """ # if the actor is not in memory then try to load it from file + loadedFromFile=False if not personCache.get(personUrl): cacheFilename=baseDir+'/cache/actors/'+personUrl.replace('/','#')+'.json' if os.path.isfile(cacheFilename): with open(cacheFilename, 'r') as fp: personJson=commentjson.load(fp) storePersonInCache(baseDir,personUrl,personJson,personCache) + loadedFromFile=True if personCache.get(personUrl): - # update the timestamp for the last time the actor was retrieved - currTime=datetime.datetime.utcnow() - personCache[personUrl]['timestamp']=currTime.strftime("%Y-%m-%dT%H:%M:%SZ") + if not loadedFromFile: + # update the timestamp for the last time the actor was retrieved + currTime=datetime.datetime.utcnow() + personCache[personUrl]['timestamp']=currTime.strftime("%Y-%m-%dT%H:%M:%SZ") return personCache[personUrl]['actor'] return None