Adds the ability to replace/extend caching backend (#7856)

* Add ability to override cache backend with custom module

* Tests for setup_cache

* Add custom CACHE_CONFIG documentation

* Fix linter errors and documentation link

* Fix black formatting errors
This commit is contained in:
Rob DiCiuccio
2019-07-12 14:06:56 -07:00
committed by Maxime Beauchemin
parent 7946165e6e
commit df051813d5
3 changed files with 58 additions and 2 deletions

View File

@@ -775,8 +775,14 @@ def choicify(values):
def setup_cache(app: Flask, cache_config) -> Optional[Cache]:
"""Setup the flask-cache on a flask app"""
if cache_config and cache_config.get("CACHE_TYPE") != "null":
return Cache(app, config=cache_config)
if cache_config:
if isinstance(cache_config, dict):
if cache_config.get("CACHE_TYPE") != "null":
return Cache(app, config=cache_config)
else:
# Accepts a custom cache initialization function,
# returning an object compatible with Flask-Caching API
return cache_config(app)
return None