diff --git a/cache.py b/cache.py index 182f14b1..44311d80 100644 --- a/cache.py +++ b/cache.py @@ -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 """ diff --git a/daemon.py b/daemon.py index 05c0f9d0..fc6a8193 100644 --- a/daemon.py +++ b/daemon.py @@ -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, \ diff --git a/inbox.py b/inbox.py index e6c9d47e..cb5fb9f9 100644 --- a/inbox.py +++ b/inbox.py @@ -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: [], \