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