fix: workaround long load times with naive in-memory caching

This commit is contained in:
2025-07-07 11:34:57 +02:00
parent 3253447c72
commit 51b94842e3
3 changed files with 15 additions and 1 deletions

View File

@@ -349,6 +349,14 @@ def videos(data):
time_start = time()
if ythdd_globals.config['general']['cache'] and data[3] in ythdd_globals.video_cache:
if ythdd_globals.video_cache[data[3]]['cacheTime'] + 3 * 60 > time():
response = ythdd_globals.video_cache[data[3]]
response['fromCache'] = True
return send(200, response)
else:
del ythdd_globals.video_cache[data[3]]
ydata = ythdd_extractor.extract(data[3], manifest_fix=True)
wdata = ythdd_extractor.WEBextractSinglePage(data[3])
@@ -587,6 +595,10 @@ def videos(data):
response["ydata"] = ydata
response["wdata"] = wdata
if ythdd_globals.config['general']['cache']:
ythdd_globals.video_cache[data[3]] = response
ythdd_globals.video_cache[data[3]]['cacheTime'] = time()
# for debugging:
#return send(200, ythdd_extractor.WEBextractSinglePage(data[3]))
#return send(200, ythdd_extractor.IOSextract(data[3]))