forked from indymedia/epicyon
Check if cache entry was loaded
parent
848d438767
commit
9b39bfee94
9
cache.py
9
cache.py
|
@ -35,17 +35,20 @@ def getPersonFromCache(baseDir: str,personUrl: str,personCache: {}) -> {}:
|
||||||
"""Get an actor from the cache
|
"""Get an actor from the cache
|
||||||
"""
|
"""
|
||||||
# if the actor is not in memory then try to load it from file
|
# if the actor is not in memory then try to load it from file
|
||||||
|
loadedFromFile=False
|
||||||
if not personCache.get(personUrl):
|
if not personCache.get(personUrl):
|
||||||
cacheFilename=baseDir+'/cache/actors/'+personUrl.replace('/','#')+'.json'
|
cacheFilename=baseDir+'/cache/actors/'+personUrl.replace('/','#')+'.json'
|
||||||
if os.path.isfile(cacheFilename):
|
if os.path.isfile(cacheFilename):
|
||||||
with open(cacheFilename, 'r') as fp:
|
with open(cacheFilename, 'r') as fp:
|
||||||
personJson=commentjson.load(fp)
|
personJson=commentjson.load(fp)
|
||||||
storePersonInCache(baseDir,personUrl,personJson,personCache)
|
storePersonInCache(baseDir,personUrl,personJson,personCache)
|
||||||
|
loadedFromFile=True
|
||||||
|
|
||||||
if personCache.get(personUrl):
|
if personCache.get(personUrl):
|
||||||
# update the timestamp for the last time the actor was retrieved
|
if not loadedFromFile:
|
||||||
currTime=datetime.datetime.utcnow()
|
# update the timestamp for the last time the actor was retrieved
|
||||||
personCache[personUrl]['timestamp']=currTime.strftime("%Y-%m-%dT%H:%M:%SZ")
|
currTime=datetime.datetime.utcnow()
|
||||||
|
personCache[personUrl]['timestamp']=currTime.strftime("%Y-%m-%dT%H:%M:%SZ")
|
||||||
return personCache[personUrl]['actor']
|
return personCache[personUrl]['actor']
|
||||||
return None
|
return None
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue