You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@superset.apache.org by jo...@apache.org on 2023/11/08 20:57:46 UTC

(superset) branch master updated: chore: Simplify utils/cache by using default argument values (#25900)

This is an automated email from the ASF dual-hosted git repository.

johnbodley pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/superset.git


The following commit(s) were added to refs/heads/master by this push:
     new 90e210892b chore: Simplify utils/cache by using default argument values (#25900)
90e210892b is described below

commit 90e210892ba5c076b47ab3007c7e027e9b405b6b
Author: Sebastian Liebscher <11...@users.noreply.github.com>
AuthorDate: Wed Nov 8 21:57:40 2023 +0100

    chore: Simplify utils/cache by using default argument values (#25900)
---
 superset/utils/cache.py | 26 +++++++-------------------
 1 file changed, 7 insertions(+), 19 deletions(-)

diff --git a/superset/utils/cache.py b/superset/utils/cache.py
index 693f3a73bc..48e283e7c1 100644
--- a/superset/utils/cache.py
+++ b/superset/utils/cache.py
@@ -89,14 +89,7 @@ ONE_YEAR = 365 * 24 * 60 * 60  # 1 year in seconds
 logger = logging.getLogger(__name__)
 
 
-def view_cache_key(*args: Any, **kwargs: Any) -> str:  # pylint: disable=unused-argument
-    args_hash = hash(frozenset(request.args.items()))
-    return f"view/{request.path}/{args_hash}"
-
-
-def memoized_func(
-    key: str | None = None, cache: Cache = cache_manager.cache
-) -> Callable[..., Any]:
+def memoized_func(key: str, cache: Cache = cache_manager.cache) -> Callable[..., Any]:
     """
     Decorator with configurable key and cache backend.
 
@@ -129,14 +122,11 @@ def memoized_func(
             if not kwargs.get("cache", True):
                 return f(*args, **kwargs)
 
-            if key:
-                # format the key using args/kwargs passed to the decorated function
-                signature = inspect.signature(f)
-                bound_args = signature.bind(*args, **kwargs)
-                bound_args.apply_defaults()
-                cache_key = key.format(**bound_args.arguments)
-            else:
-                cache_key = view_cache_key(*args, **kwargs)
+            # format the key using args/kwargs passed to the decorated function
+            signature = inspect.signature(f)
+            bound_args = signature.bind(*args, **kwargs)
+            bound_args.apply_defaults()
+            cache_key = key.format(**bound_args.arguments)
 
             obj = cache.get(cache_key)
             if not kwargs.get("force") and obj is not None:
@@ -153,7 +143,7 @@ def memoized_func(
 def etag_cache(
     cache: Cache = cache_manager.cache,
     get_last_modified: Callable[..., datetime] | None = None,
-    max_age: int | float | None = None,
+    max_age: int | float = app.config["CACHE_DEFAULT_TIMEOUT"],
     raise_for_access: Callable[..., Any] | None = None,
     skip: Callable[..., bool] | None = None,
 ) -> Callable[..., Any]:
@@ -169,8 +159,6 @@ def etag_cache(
     dataframe cache for requests that produce the same SQL.
 
     """
-    if max_age is None:
-        max_age = app.config["CACHE_DEFAULT_TIMEOUT"]
 
     def decorator(f: Callable[..., Any]) -> Callable[..., Any]:
         @wraps(f)