michael-s-molina commented on a change in pull request #18976:
URL: https://github.com/apache/superset/pull/18976#discussion_r817871711



##########
File path: superset/utils/cache_manager.py
##########
@@ -28,41 +34,47 @@ def __init__(self) -> None:
         self._filter_state_cache = Cache()
         self._explore_form_data_cache = Cache()
 
+    @staticmethod
+    def _init_cache(
+        app: Flask, cache: Cache, cache_config_key: str, required: bool = False
+    ) -> None:
+        cache_config = app.config[cache_config_key]
+        cache_type = cache_config.get("CACHE_TYPE")
+        if app.debug and cache_type is None:
+            cache_threshold = cache_config.get("CACHE_THRESHOLD", math.inf)
+            cache_config.update(
+                {"CACHE_TYPE": "SimpleCache", "CACHE_THRESHOLD": 
cache_threshold,}
+            )
+
+        if "CACHE_DEFAULT_TIMEOUT" not in cache_config:
+            default_timeout = app.config.get("CACHE_DEFAULT_TIMEOUT")
+            cache_config["CACHE_DEFAULT_TIMEOUT"] = default_timeout
+
+        if required and cache_type in ("null", "NullCache"):
+            raise Exception(
+                _(
+                    "The CACHE_TYPE `%(cache_type)s` for 
`%(cache_config_key)s` is not "
+                    "supported. It is recommended to use `RedisCache`, "
+                    "`MemcachedCache` or another dedicated caching backend for 
"
+                    "production deployments",
+                    cache_type=cache_config["CACHE_TYPE"],
+                    cache_config_key=cache_config_key,
+                ),
+            )
+        cache.init_app(app, cache_config)
+
     def init_app(self, app: Flask) -> None:
-        self._cache.init_app(
-            app,
-            {
-                "CACHE_DEFAULT_TIMEOUT": app.config["CACHE_DEFAULT_TIMEOUT"],
-                **app.config["CACHE_CONFIG"],
-            },
-        )
-        self._data_cache.init_app(
-            app,
-            {
-                "CACHE_DEFAULT_TIMEOUT": app.config["CACHE_DEFAULT_TIMEOUT"],
-                **app.config["DATA_CACHE_CONFIG"],
-            },
-        )
-        self._thumbnail_cache.init_app(
-            app,
-            {
-                "CACHE_DEFAULT_TIMEOUT": app.config["CACHE_DEFAULT_TIMEOUT"],
-                **app.config["THUMBNAIL_CACHE_CONFIG"],
-            },
-        )
-        self._filter_state_cache.init_app(
-            app,
-            {
-                "CACHE_DEFAULT_TIMEOUT": app.config["CACHE_DEFAULT_TIMEOUT"],
-                **app.config["FILTER_STATE_CACHE_CONFIG"],
-            },
+        self._init_cache(app, self._cache, "CACHE_CONFIG")
+        self._init_cache(app, self._data_cache, "DATA_CACHE_CONFIG")
+        self._init_cache(app, self._thumbnail_cache, "THUMBNAIL_CACHE_CONFIG")
+        self._init_cache(
+            app, self._filter_state_cache, "FILTER_STATE_CACHE_CONFIG", 
required=True

Review comment:
       Not required but it would be a good idea to extract these strings are 
constants to avoid typing errors.




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]



---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to