Log cache hits and misses
This commit is contained in:
parent
d7422926ad
commit
8e8b460975
1 changed files with 12 additions and 6 deletions
18
server.py
18
server.py
|
@ -224,12 +224,18 @@ def preview_url(
|
|||
if ts is None or abs(ts - _ts) < 3600:
|
||||
logging.debug("Optimal cache hit for %r", url)
|
||||
return json.loads(metadata)
|
||||
# No close matches, get the latest one
|
||||
metadata, _ts = results[-1]
|
||||
# If the latest one is more than 3 hours old, re-fetch. Otherwise, return.
|
||||
if ts is None or abs(ts - _ts) < 10800:
|
||||
logging.debug("Cache hit for %r", url)
|
||||
return json.loads(metadata)
|
||||
else:
|
||||
logging.debug("No optimal cache matches for url %r.", url)
|
||||
# No close matches, get the latest one
|
||||
metadata, _ts = results[-1]
|
||||
# If the latest one is more than a week old, re-fetch. Otherwise, return.
|
||||
if ts is None or abs(ts - _ts) < 604800:
|
||||
logging.debug("Stale cache hit for %r", url)
|
||||
return json.loads(metadata)
|
||||
else:
|
||||
logging.debug("Cache miss for %r")
|
||||
else:
|
||||
logging.debug("Full cache miss for %r", url)
|
||||
|
||||
domain = os.environ.get("PREVIEW_HOMESERVER", "https://" + req.url.hostname)
|
||||
with lock:
|
||||
|
|
Loading…
Reference in a new issue