diff --git a/superset/__init__.py b/superset/__init__.py index 3e26c3fb74b45..2d76afd5284bd 100644 --- a/superset/__init__.py +++ b/superset/__init__.py @@ -40,7 +40,7 @@ # then initialize it in app.create_app(). These fields will be removed # in subsequent PRs as things are migrated towards the factory pattern app: Flask = current_app -cache = LocalProxy(lambda: cache_manager.cache) +cache = cache_manager.cache conf = LocalProxy(lambda: current_app.config) get_feature_flags = feature_flag_manager.get_feature_flags get_manifest_files = manifest_processor.get_manifest_files diff --git a/superset/utils/cache_manager.py b/superset/utils/cache_manager.py index 4a625ea6d00bb..adb5628fec3ef 100644 --- a/superset/utils/cache_manager.py +++ b/superset/utils/cache_manager.py @@ -24,28 +24,24 @@ class CacheManager: def __init__(self) -> None: super().__init__() - self._tables_cache = None - self._cache = None - self._thumbnail_cache = None + self._cache = self._setup_cache(app.config["CACHE_CONFIG"]) + self._tables_cache = self._setup_cache(app.config["TABLE_NAMES_CACHE_CONFIG"]) + self._thumbnail_cache = self._setup_cache(app.config["THUMBNAIL_CACHE_CONFIG"]) def init_app(self, app: Flask) -> None: - self._cache = self._setup_cache(app, app.config["CACHE_CONFIG"]) - self._tables_cache = self._setup_cache( - app, app.config["TABLE_NAMES_CACHE_CONFIG"] - ) - self._thumbnail_cache = self._setup_cache( - app, app.config["THUMBNAIL_CACHE_CONFIG"] - ) + self._cache.init_app(app) + self._tables_cache.init_app(app) + self._thumbnail_cache.init_app(app) @staticmethod - def _setup_cache(app: Flask, cache_config: CacheConfig) -> Cache: + def _setup_cache(cache_config: CacheConfig) -> Cache: """Setup the flask-cache on a flask app""" if isinstance(cache_config, dict): - return Cache(app, config=cache_config) + return Cache(config=cache_config) # Accepts a custom cache initialization function, returning an object compatible # with Flask-Caching API. - return cache_config(app) + return cache_config() @property def tables_cache(self) -> Cache: