You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@superset.apache.org by GitBox <gi...@apache.org> on 2022/03/01 17:02:12 UTC

[GitHub] [superset] michael-s-molina commented on a change in pull request #18976: chore(cache): default to SimpleCache in debug mode

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



##########
File path: superset/config.py
##########
@@ -576,29 +577,43 @@ def _try_json_readsha(filepath: str, length: int) -> Optional[str]:
 # Setup image size default is (300, 200, True)
 # IMG_SIZE = (300, 200, True)
 
-# Default cache timeout, applies to all cache backends unless specifically overridden in
+
+# Default cache config, applies to all cache backends unless specifically overridden in
 # each cache config.
-CACHE_DEFAULT_TIMEOUT = int(timedelta(days=1).total_seconds())
+def DEFAULT_CACHE_CONFIG_FUNC(  # pylint: disable=invalid-name
+    app: Flask,
+) -> CacheConfig:
+    default_timeout = app.config.get("CACHE_DEFAULT_TIMEOUT")
+    if default_timeout is None:
+        default_timeout = int(timedelta(days=1).total_seconds())
+    else:
+        logger.warning(
+            "The config flag CACHE_DEFAULT_TIMEOUT has been deprecated "
+            "and will be removed in Superset 2.0. Please set default cache options in "
+            "DEFAULT_CACHE_CONFIG_FUNC"
+        )
+
+    return {
+        "CACHE_TYPE": "SimpleCache" if app.debug else "NullCache",

Review comment:
       I think it would be a good idea to warn the user when the cache is set to `NullCache` because it effectively disables the cache. This may occur because the administrator forgot to configure it properly. If not a global message, then at least for Explore/dashboard states because they won't work properly.

##########
File path: superset/utils/cache_manager.py
##########
@@ -29,40 +29,22 @@ def __init__(self) -> None:
         self._explore_form_data_cache = Cache()
 
     def init_app(self, app: Flask) -> None:
+        default_cache_config = app.config["DEFAULT_CACHE_CONFIG_FUNC"](app)
         self._cache.init_app(
-            app,
-            {
-                "CACHE_DEFAULT_TIMEOUT": app.config["CACHE_DEFAULT_TIMEOUT"],
-                **app.config["CACHE_CONFIG"],
-            },
+            app, {**default_cache_config, **app.config["CACHE_CONFIG"]},
         )
         self._data_cache.init_app(
-            app,
-            {
-                "CACHE_DEFAULT_TIMEOUT": app.config["CACHE_DEFAULT_TIMEOUT"],
-                **app.config["DATA_CACHE_CONFIG"],
-            },
+            app, {**default_cache_config, **app.config["DATA_CACHE_CONFIG"]},
         )
         self._thumbnail_cache.init_app(
-            app,
-            {
-                "CACHE_DEFAULT_TIMEOUT": app.config["CACHE_DEFAULT_TIMEOUT"],
-                **app.config["THUMBNAIL_CACHE_CONFIG"],
-            },
+            app, {**default_cache_config, **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"],
-            },
+            app, {**default_cache_config, **app.config["FILTER_STATE_CACHE_CONFIG"]},
         )
         self._explore_form_data_cache.init_app(
             app,
-            {
-                "CACHE_DEFAULT_TIMEOUT": app.config["CACHE_DEFAULT_TIMEOUT"],
-                **app.config["EXPLORE_FORM_DATA_CACHE_CONFIG"],
-            },
+            {**default_cache_config, **app.config["EXPLORE_FORM_DATA_CACHE_CONFIG"],},

Review comment:
       ```suggestion
               {**default_cache_config, **app.config["EXPLORE_FORM_DATA_CACHE_CONFIG"]},
   ```




-- 
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: notifications-unsubscribe@superset.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For additional commands, e-mail: notifications-help@superset.apache.org