From a5427a4ca2cfe4e8b7b720e814bcd6c439d3adb1 Mon Sep 17 00:00:00 2001 From: Nikolai Prokoschenko Date: Mon, 22 Apr 2024 09:13:23 +0200 Subject: [PATCH] Add request caching to Dockerfile generator When developing parts of the Dockerfile generation pipeline, and thus regenerating Dockerfiles over and over, many unnecessary HTTP requests are being made to https://api.adoptium.net, since the data is mostly unchanged. Adding a request cache with an expiration time of an hour allows this regeneration to run in under a second in most case, while not compromising on the correctness. --- .gitignore | 1 + generate_dockerfiles.py | 3 +++ requirements.txt | 1 + 3 files changed, 5 insertions(+) diff --git a/.gitignore b/.gitignore index b9de93e59..081ed0847 100644 --- a/.gitignore +++ b/.gitignore @@ -11,3 +11,4 @@ official-eclipse-temurin library/ .vscode/ __pycache__/ +/adoptium_cache.sqlite diff --git a/generate_dockerfiles.py b/generate_dockerfiles.py index e3c32cf9e..8865a78a4 100644 --- a/generate_dockerfiles.py +++ b/generate_dockerfiles.py @@ -13,10 +13,13 @@ import os +import requests_cache import requests import yaml from jinja2 import Environment, FileSystemLoader +requests_cache.install_cache("adoptium_cache", expire_after=3600) + # Setup the Jinja2 environment env = Environment(loader=FileSystemLoader("docker_templates")) diff --git a/requirements.txt b/requirements.txt index 33c43e26b..bebb236fa 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,3 +1,4 @@ Jinja2==3.1.3 PyYAML==6.0.1 Requests==2.31.0 +requests-cache==1.2.0