fix: workaround long load times with naive in-memory caching
This commit is contained in:
@@ -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]))
|
||||
|
||||
Reference in New Issue
Block a user