chore: Using cache factory method (#10887)

Co-authored-by: John Bodley <john.bodley@airbnb.com>
This commit is contained in:
John Bodley
2020-09-15 12:48:19 -07:00
committed by GitHub
parent 9c420d6efe
commit b48dd4b7d9
6 changed files with 18 additions and 83 deletions

View File

@@ -34,23 +34,7 @@ CACHE_CONFIG = {
}
```
It is also possible to pass a custom cache initialization function in the config to handle
additional caching use cases. The function must return an object that is compatible with the
[Flask-Cache API](https://pythonhosted.org/Flask-Cache/).
```python
from custom_caching import CustomCache
def init_cache(app):
"""Takes an app instance and returns a custom cache backend"""
config = {
'CACHE_DEFAULT_TIMEOUT': 60 * 60 * 24, # 1 day default (in secs)
'CACHE_KEY_PREFIX': 'superset_results',
}
return CustomCache(app, config)
CACHE_CONFIG = init_cache
```
Custom cache backends are also supported. See [here](https://flask-caching.readthedocs.io/en/latest/#custom-cache-backends) for specifics.
Superset has a Celery task that will periodically warm up the cache based on different strategies.
To use it, add the following to the `CELERYBEAT_SCHEDULE` section in `config.py`: