michael-s-molina commented on a change in pull request #18976:
URL: https://github.com/apache/superset/pull/18976#discussion_r817619939
##########
File path: superset/utils/cache_manager.py
##########
@@ -14,73 +14,78 @@
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
+import logging
+import math
+
from flask import Flask
+from flask_babel import gettext as _
from flask_caching import Cache
+from superset.typing import CacheConfig
+
+logger = logging.getLogger(__name__)
+
class CacheManager:
def __init__(self) -> None:
super().__init__()
- self._cache = Cache()
- self._data_cache = Cache()
- self._thumbnail_cache = Cache()
- self._filter_state_cache = Cache()
- self._explore_form_data_cache = Cache()
+ self._default_cache_config: CacheConfig = {}
+ self.cache = Cache()
+ self.data_cache = Cache()
+ self.thumbnail_cache = Cache()
+ self.filter_state_cache = Cache()
+ self.explore_form_data_cache = Cache()
+
+ def _init_cache(
+ self, app: Flask, cache: Cache, cache_config_key: str, required: bool
= False
+ ) -> None:
+ config = {**self._default_cache_config, **app.config[cache_config_key]}
+ if required and config["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=config["CACHE_TYPE"],
+ cache_config_key=cache_config_key,
+ ),
+ )
+ cache.init_app(app, 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"],
- },
+ if app.debug:
+ self._default_cache_config = {
+ "CACHE_TYPE": "SimpleCache",
+ "CACHE_THRESHOLD": math.inf,
+ }
+ else:
+ self._default_cache_config = {}
Review comment:
Is this required? `_default_cache_config` is already being initialized
in the constructor.
--
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]