robdiciuccio commented on a change in pull request #11499:
URL:
https://github.com/apache/incubator-superset/pull/11499#discussion_r520952889
##########
File path: superset/utils/cache.py
##########
@@ -14,11 +14,51 @@
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
-from typing import Any, Callable, Optional
+import hashlib
+import json
+import logging
+from datetime import datetime
+from typing import Any, Callable, Dict, Optional
from flask import request
+from flask_caching import Cache
+from superset import app, utils
from superset.extensions import cache_manager
+from superset.stats_logger import BaseStatsLogger
+from superset.utils.core import json_int_dttm_ser
+
+config = app.config
+stats_logger: BaseStatsLogger = config["STATS_LOGGER"]
+logger = logging.getLogger(__name__)
+
+# TODO: DRY up cache key code
+def json_dumps(obj: Any, sort_keys: bool = False) -> str:
+ return json.dumps(obj, default=json_int_dttm_ser, sort_keys=sort_keys)
+
+
+def generate_cache_key(values_dict: Dict[str, Any], key_prefix: str = "") ->
str:
+ json_data = json_dumps(values_dict, sort_keys=True)
+ hash = hashlib.md5(json_data.encode("utf-8")).hexdigest()
+ return f"{key_prefix}{hash}"
+
+
+def set_and_log_cache(
Review comment:
@bkyryliuk I'm starting to move/centralize the caching logic, and have
not included the `CacheKey` write that is present in the `viz.py`
implementation because 1) I don't understand the use case, and 2) we can't
afford the performance hit of writing to the metadata DB in the same method
that writes to a K/V store (we're currently using Redis). Can you elaborate on
`CacheKey` and how it's used?
----------------------------------------------------------------
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.
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]