commit 08c60e202b93b69e04b2932ac94ae55dfb6096d2
parent 0f328141b91ead6a43741030626f6f56ee96cebd
Author: Solderpunk <solderpunk@sdf.org>
Date: Sun, 30 Aug 2020 23:17:21 +0200
Turn some magic numbers into constants.
Diffstat:
1 file changed, 5 insertions(+), 3 deletions(-)
diff --git a/av98.py b/av98.py
@@ -54,6 +54,8 @@ except ModuleNotFoundError:
_VERSION = "1.0.2dev"
_MAX_REDIRECTS = 5
+_MAX_CACHE_SIZE = 10
+_MAX_CACHE_AGE_SECS = 180
# Command abbreviations
_ABBREVS = {
@@ -672,7 +674,7 @@ you'll be able to transparently follow links to Gopherspace!""")
return False
now = time.time()
cached = self.cache_timestamps[url]
- if now - cached > 180:
+ if now - cached > _MAX_CACHE_AGE_SECS:
self._debug("Expiring old cached copy of resource.")
self._remove_from_cache(url)
return False
@@ -689,7 +691,7 @@ you'll be able to transparently follow links to Gopherspace!""")
self.cache_timestamps[url] = time.time()
self.cache[url] = (mime, filename)
- if len(self.cache) > 10:
+ if len(self.cache) > _MAX_CACHE_SIZE:
self._trim_cache()
self._validate_cache()
@@ -704,7 +706,7 @@ you'll be able to transparently follow links to Gopherspace!""")
# Drop other entries if they are older than the limit
now = time.time()
for cached, url in lru[1:]:
- if now - cached > 180:
+ if now - cached > _MAX_CACHE_AGE_SECS:
self._debug("Dropping cached copy of {} from full cache.".format(url))
self._remove_from_cache(url)
else: