Thread for cache expiry

master
Bob Mottram 2019-08-20 11:28:05 +01:00
parent 97799f1db2
commit 25b2f3210b
3 changed files with 16 additions and 1 deletions

View File

@ -65,6 +65,14 @@ def expirePersonCache(personCache: {}):
del personCache[personUrl]
print(str(len(removals))+' actors were expired from the cache')
def expireCache(baseDir: str,personCache: {}):
"""Cache expiry thread
"""
while True:
# once per day
time.sleep(60*60*24)
expirePersonCache(basedir,personCache)
def storeWebfingerInCache(handle: str,wf,cachedWebfingers: {}) -> None:
"""Store a webfinger endpoint in the cache
"""

View File

@ -109,6 +109,7 @@ from announce import createAnnounce
from announce import outboxAnnounce
from content import addHtmlTags
from media import removeMetaData
from cache import expireCache
import os
import sys
@ -2940,6 +2941,12 @@ def runDaemon(projectVersion, \
print('Creating actors cache')
os.mkdir(baseDir+'/cache/actors')
print('Creating cache expiry thread')
httpd.thrCache= \
threadWithTrace(target=expireCache, \
args=(baseDir,httpd.personCache),daemon=True)
httpd.thrCache.start()
print('Creating inbox queue')
httpd.thrInboxQueue= \
threadWithTrace(target=runInboxQueue, \

View File

@ -1037,7 +1037,7 @@ def restoreQueueItems(baseDir: str,queue: []) -> None:
queue.append(os.path.join(queueDir, qfile))
if len(queue)>0:
print('Restored '+str(len(queue))+' inbox queue items')
def runInboxQueue(projectVersion: str, \
baseDir: str,httpPrefix: str,sendThreads: [],postLog: [], \
cachedWebfingers: {},personCache: {},queue: [], \