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] del personCache[personUrl]
print(str(len(removals))+' actors were expired from the cache') 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: def storeWebfingerInCache(handle: str,wf,cachedWebfingers: {}) -> None:
"""Store a webfinger endpoint in the cache """Store a webfinger endpoint in the cache
""" """

View File

@ -109,6 +109,7 @@ from announce import createAnnounce
from announce import outboxAnnounce from announce import outboxAnnounce
from content import addHtmlTags from content import addHtmlTags
from media import removeMetaData from media import removeMetaData
from cache import expireCache
import os import os
import sys import sys
@ -2940,6 +2941,12 @@ def runDaemon(projectVersion, \
print('Creating actors cache') print('Creating actors cache')
os.mkdir(baseDir+'/cache/actors') 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') print('Creating inbox queue')
httpd.thrInboxQueue= \ httpd.thrInboxQueue= \
threadWithTrace(target=runInboxQueue, \ threadWithTrace(target=runInboxQueue, \