Commit fd5c219e authored by Pierre Dittgen's avatar Pierre Dittgen

Change cache policy

parent 336265e9
......@@ -53,6 +53,7 @@ setup(
install_requires=[
'backports-datetime-fromisoformat',
'cachecontrol',
'cachetools',
'commonmark',
'ezodf',
......
......@@ -4,6 +4,7 @@ import os
from pathlib import Path
from urllib.parse import quote_plus
import cachecontrol
import flask
import jinja2
import requests
......@@ -17,11 +18,6 @@ from . import config
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)
def schema_from_url(url):
return tableschema.Schema(url)
......@@ -31,11 +27,12 @@ def schema_from_url(url):
schema_catalog_map = {}
if config.HOMEPAGE_CONFIG:
log.info("Initializing homepage sections...")
caching_session = cachecontrol.CacheControl(requests.Session())
for section in config.HOMEPAGE_CONFIG['sections']:
if isinstance(section['catalog'], str) and section['catalog'].startswith('http'):
code = section['code']
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
app = flask.Flask(__name__)
......
......@@ -31,7 +31,7 @@ block head %}
<h4 class="card-title">{{ val.title }}</h4>
<p class="card-text">{{ val.description }}</p>
<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"
>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