1
0
forked from ScoDoc/ScoDoc

Env. var specifying cache type

This commit is contained in:
Emmanuel Viennet 2022-03-12 09:39:28 +01:00
parent 26ad2ba59b
commit dcc06d6169

View File

@ -43,11 +43,13 @@ mail = Mail()
bootstrap = Bootstrap()
moment = Moment()
cache = Cache( # XXX TODO: configuration file
CACHE_TYPE = os.environ.get("CACHE_TYPE")
cache = Cache(
config={
# see https://flask-caching.readthedocs.io/en/latest/index.html#configuring-flask-caching
"CACHE_TYPE": "RedisCache",
"CACHE_DEFAULT_TIMEOUT": 0, # by default, never expire
"CACHE_TYPE": CACHE_TYPE or "RedisCache",
# by default, never expire:
"CACHE_DEFAULT_TIMEOUT": os.environ.get("CACHE_DEFAULT_TIMEOUT") or 0,
}
)
@ -187,6 +189,8 @@ def create_app(config_class=DevConfig):
moment.init_app(app)
cache.init_app(app)
sco_cache.CACHE = cache
if CACHE_TYPE: # non default
app.logger.info(f"CACHE_TYPE={CACHE_TYPE}")
app.register_error_handler(ScoGenError, handle_sco_value_error)
app.register_error_handler(ScoValueError, handle_sco_value_error)