Commit fd5c219e authored by Pierre Dittgen's avatar Pierre Dittgen

Change cache policy

parent 336265e9
backports-datetime-fromisoformat==1.0.0 backports-datetime-fromisoformat==1.0.0
cachecontrol==0.12.5
cachetools==3.1.1 cachetools==3.1.1
commonmark==0.8.1 commonmark==0.8.1
ezodf==0.3.2 ezodf==0.3.2
Flask==1.0.2 Flask==1.0.2
lxml==4.2.5 lxml==4.2.5
opendataschema==0.2.0
python-dotenv==0.10.1 python-dotenv==0.10.1
requests==2.22.0 requests==2.22.0
toml==0.10.0 toml==0.10.0
tabulator==1.21.0 tabulator==1.21.0
opendataschema==0.2.0
validata_core==0.3.4 validata_core==0.3.4
...@@ -53,6 +53,7 @@ setup( ...@@ -53,6 +53,7 @@ setup(
install_requires=[ install_requires=[
'backports-datetime-fromisoformat', 'backports-datetime-fromisoformat',
'cachecontrol',
'cachetools', 'cachetools',
'commonmark', 'commonmark',
'ezodf', 'ezodf',
......
...@@ -4,6 +4,7 @@ import os ...@@ -4,6 +4,7 @@ import os
from pathlib import Path from pathlib import Path
from urllib.parse import quote_plus from urllib.parse import quote_plus
import cachecontrol
import flask import flask
import jinja2 import jinja2
import requests import requests
...@@ -17,11 +18,6 @@ from . import config ...@@ -17,11 +18,6 @@ from . import config
log = logging.getLogger(__name__) log = logging.getLogger(__name__)
@ttl_cache(maxsize=50, ttl=5*60)
def download_with_cache(url):
return requests.get(url)
@ttl_cache(maxsize=24, ttl=5*60) @ttl_cache(maxsize=24, ttl=5*60)
def schema_from_url(url): def schema_from_url(url):
return tableschema.Schema(url) return tableschema.Schema(url)
...@@ -31,11 +27,12 @@ def schema_from_url(url): ...@@ -31,11 +27,12 @@ def schema_from_url(url):
schema_catalog_map = {} schema_catalog_map = {}
if config.HOMEPAGE_CONFIG: if config.HOMEPAGE_CONFIG:
log.info("Initializing homepage sections...") log.info("Initializing homepage sections...")
caching_session = cachecontrol.CacheControl(requests.Session())
for section in config.HOMEPAGE_CONFIG['sections']: for section in config.HOMEPAGE_CONFIG['sections']:
if isinstance(section['catalog'], str) and section['catalog'].startswith('http'): if isinstance(section['catalog'], str) and section['catalog'].startswith('http'):
code = section['code'] code = section['code']
url = section['catalog'] url = section['catalog']
schema_catalog_map[code] = opendataschema.SchemaCatalog(url, download_func=download_with_cache) schema_catalog_map[code] = opendataschema.SchemaCatalog(url, session=caching_session)
# Flask things # Flask things
app = flask.Flask(__name__) app = flask.Flask(__name__)
......
...@@ -31,7 +31,7 @@ block head %} ...@@ -31,7 +31,7 @@ block head %}
<h4 class="card-title">{{ val.title }}</h4> <h4 class="card-title">{{ val.title }}</h4>
<p class="card-text">{{ val.description }}</p> <p class="card-text">{{ val.description }}</p>
<a <a
href="{{ url_for('custom_validator') }}?schema_name={{val.name}}" href="{{ url_for('custom_validator') }}?schema_name={{val.name}}&schema_ref=master"
class="btn btn-primary mt-auto" class="btn btn-primary mt-auto"
>Choisir</a >Choisir</a
> >
......
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