Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
Validata
Validata UI
Commits
6e974a24
Commit
6e974a24
authored
Jan 15, 2021
by
Pierre Dittgen
Browse files
Rename CACHING_EXPIRE_AFTER into CACHE_EXPIRE_AFTER, add CACHE_BACKEND
parent
26d5aed0
Changes
3
Hide whitespace changes
Inline
Side-by-side
.env.example
View file @
6e974a24
...
...
@@ -26,4 +26,8 @@ CONFIG=config.example.yaml
# BROWSERLESS_API_TOKEN="XXX"
# Number of minutes to cache downloaded schemas
# CACHING_EXPIRE_AFTER=0
\ No newline at end of file
# CACHE_EXPIRE_AFTER=0
#
# 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
validata_ui/__init__.py
View file @
6e974a24
...
...
@@ -45,9 +45,11 @@ class SchemaCatalogRegistry:
return
opendataschema
.
SchemaCatalog
(
ref
,
session
=
self
.
session
)
expire_after
=
timedelta
(
minutes
=
config
.
CACH
ING
_EXPIRE_AFTER
)
expire_after
=
timedelta
(
minutes
=
config
.
CACH
E
_EXPIRE_AFTER
)
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
)
...
...
validata_ui/config.py
View file @
6e974a24
...
...
@@ -85,17 +85,21 @@ SENTRY_DSN = os.environ.get("SENTRY_DSN")
BROWSERLESS_API_URL
=
os
.
getenv
(
"BROWSERLESS_API_URL"
)
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
CACH
ING
_EXPIRE_AFTER
=
os
.
getenv
(
"CACH
ING
_EXPIRE_AFTER"
)
or
None
if
CACH
ING
_EXPIRE_AFTER
is
None
:
CACH
E
_EXPIRE_AFTER
=
os
.
getenv
(
"CACH
E
_EXPIRE_AFTER"
)
or
None
if
CACH
E
_EXPIRE_AFTER
is
None
:
log
.
info
(
"CACH
ING
_EXPIRE_AFTER environment variable not set, using default 0 (no cache)"
"CACH
E
_EXPIRE_AFTER environment variable not set, using default 0 (no cache)"
)
CACH
ING
_EXPIRE_AFTER
=
"0"
CACH
E
_EXPIRE_AFTER
=
"0"
try
:
CACH
ING
_EXPIRE_AFTER
=
int
(
CACH
ING
_EXPIRE_AFTER
)
log
.
info
(
"Cach
ing is
set to %sm"
,
CACH
ING
_EXPIRE_AFTER
)
CACH
E
_EXPIRE_AFTER
=
int
(
CACH
E
_EXPIRE_AFTER
)
log
.
info
(
"Cach
e timeout
set to %sm"
,
CACH
E
_EXPIRE_AFTER
)
except
ValueError
as
exc
:
raise
ValueError
(
f
"Invalid number of minutes for caching:
{
CACH
ING
_EXPIRE_AFTER
}
"
f
"Invalid number of minutes for caching:
{
CACH
E
_EXPIRE_AFTER
}
"
)
from
exc
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment