diff --git a/usr/lib/python3.8/spoc/repo_local.py b/usr/lib/python3.8/spoc/repo_local.py index 12e2152..5e36c9a 100644 --- a/usr/lib/python3.8/spoc/repo_local.py +++ b/usr/lib/python3.8/spoc/repo_local.py @@ -9,7 +9,7 @@ from .config import REPO_FILE, REPO_LOCK_FILE, TYPE_APP, TYPE_CONTAINER, TYPE_IM from .flock import locked data = {TYPE_IMAGE: {}, TYPE_CONTAINER: {}, TYPE_APP: {}} -mtime = None +mtime = 0 def load(): global data diff --git a/usr/lib/python3.8/spoc/repo_online.py b/usr/lib/python3.8/spoc/repo_online.py index 4cd7220..ca11923 100644 --- a/usr/lib/python3.8/spoc/repo_online.py +++ b/usr/lib/python3.8/spoc/repo_online.py @@ -67,10 +67,13 @@ def unpack_archive(archive_path, destination, expected_hash, observer): os.unlink(archive_path) data = None +mtime = 0 def load(): global data - if not data: + global mtime + # Cache the result for 10 seconds + if mtime < time.time()-10: with requests.Session() as session: resource = session.get(ONLINE_REPO_URL, timeout=5) resource.raise_for_status() @@ -80,6 +83,7 @@ def load(): packages_sig = resource.content PUBLIC_KEY.verify(packages_sig, packages, ec.ECDSA(hashes.SHA512())) data = json.loads(packages.decode()) + mtime = time.time() def get_entries(entry_type): load() diff --git a/usr/lib/python3.8/spoc/repo_publish.py b/usr/lib/python3.8/spoc/repo_publish.py index cca0822..f007ccf 100644 --- a/usr/lib/python3.8/spoc/repo_publish.py +++ b/usr/lib/python3.8/spoc/repo_publish.py @@ -35,7 +35,7 @@ def sign_file(file_path): return private_key.sign(hasher.finalize(), ec.ECDSA(utils.Prehashed(sha512))) data = {TYPE_IMAGE: {}, TYPE_APP: {}} -mtime = None +mtime = 0 def load(): global data