Commit 6e974a24 authored by Pierre Dittgen's avatar Pierre Dittgen
Browse files

Rename CACHING_EXPIRE_AFTER into CACHE_EXPIRE_AFTER, add CACHE_BACKEND

parent 26d5aed0
...@@ -26,4 +26,8 @@ CONFIG=config.example.yaml ...@@ -26,4 +26,8 @@ CONFIG=config.example.yaml
# BROWSERLESS_API_TOKEN="XXX" # BROWSERLESS_API_TOKEN="XXX"
# Number of minutes to cache downloaded schemas # Number of minutes to cache downloaded schemas
# CACHING_EXPIRE_AFTER=0 # CACHE_EXPIRE_AFTER=0
\ No newline at end of file #
# Cache backend (default 'sqlite')
# See https://requests-cache.readthedocs.io/en/latest/user_guide.html#persistence
# CACHE_BACKEND="sqlite"
\ No newline at end of file
...@@ -45,9 +45,11 @@ class SchemaCatalogRegistry: ...@@ -45,9 +45,11 @@ class SchemaCatalogRegistry:
return opendataschema.SchemaCatalog(ref, session=self.session) return opendataschema.SchemaCatalog(ref, session=self.session)
expire_after = timedelta(minutes=config.CACHING_EXPIRE_AFTER) expire_after = timedelta(minutes=config.CACHE_EXPIRE_AFTER)
caching_session = requests_cache.CachedSession( caching_session = requests_cache.CachedSession(
backend="sqlite", cache_name="validata_ui_cache", expire_after=expire_after backend=config.CACHE_BACKEND,
cache_name="validata_ui_cache",
expire_after=expire_after,
) )
fetch_schema = generate_schema_from_url_func(caching_session) fetch_schema = generate_schema_from_url_func(caching_session)
......
...@@ -85,17 +85,21 @@ SENTRY_DSN = os.environ.get("SENTRY_DSN") ...@@ -85,17 +85,21 @@ SENTRY_DSN = os.environ.get("SENTRY_DSN")
BROWSERLESS_API_URL = os.getenv("BROWSERLESS_API_URL") or None BROWSERLESS_API_URL = os.getenv("BROWSERLESS_API_URL") or None
BROWSERLESS_API_TOKEN = os.getenv("BROWSERLESS_API_TOKEN") or None BROWSERLESS_API_TOKEN = os.getenv("BROWSERLESS_API_TOKEN") or None
# Cache backend (default is SQLite)
CACHE_BACKEND = os.getenv("CACHE_BACKEND") or "sqlite"
log.info(f"Cache backend: {CACHE_BACKEND}")
# Caching time for schema requests in minutes # Caching time for schema requests in minutes
CACHING_EXPIRE_AFTER = os.getenv("CACHING_EXPIRE_AFTER") or None CACHE_EXPIRE_AFTER = os.getenv("CACHE_EXPIRE_AFTER") or None
if CACHING_EXPIRE_AFTER is None: if CACHE_EXPIRE_AFTER is None:
log.info( log.info(
"CACHING_EXPIRE_AFTER environment variable not set, using default 0 (no cache)" "CACHE_EXPIRE_AFTER environment variable not set, using default 0 (no cache)"
) )
CACHING_EXPIRE_AFTER = "0" CACHE_EXPIRE_AFTER = "0"
try: try:
CACHING_EXPIRE_AFTER = int(CACHING_EXPIRE_AFTER) CACHE_EXPIRE_AFTER = int(CACHE_EXPIRE_AFTER)
log.info("Caching is set to %sm", CACHING_EXPIRE_AFTER) log.info("Cache timeout set to %sm", CACHE_EXPIRE_AFTER)
except ValueError as exc: except ValueError as exc:
raise ValueError( raise ValueError(
f"Invalid number of minutes for caching: {CACHING_EXPIRE_AFTER}" f"Invalid number of minutes for caching: {CACHE_EXPIRE_AFTER}"
) from exc ) from exc
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment