betodealmeida commented on a change in pull request #7227: Improve cache
URL: 
https://github.com/apache/incubator-superset/pull/7227#discussion_r273579674
 
 

 ##########
 File path: superset/utils/decorators.py
 ##########
 @@ -61,30 +62,47 @@ def wrapper(*args, **kwargs):
             # check if the user can access the resource
             check_perms(*args, **kwargs)
 
-            try:
-                # build the cache key from the function arguments and any other
-                # additional GET arguments (like `form_data`, eg).
-                key_args = list(args)
-                key_kwargs = kwargs.copy()
-                key_kwargs.update(request.args)
-                cache_key = wrapper.make_cache_key(f, *key_args, **key_kwargs)
-                response = cache.get(cache_key)
-            except Exception:  # pylint: disable=broad-except
-                if app.debug:
-                    raise
-                logging.exception('Exception possibly due to cache backend.')
-                response = None
-
-            if response is None or request.method == 'POST':
+            # for POST requests we can't set headers, use the response cache
+            # nor use conditional requests; this will still use the dataframe
+            # cache in `superset/viz.py`, though.
+            if request.method == 'POST':
+                return f(*args, **kwargs)
+
+            response = None
+            if cache:
+                try:
+                    # build the cache key from the function arguments and any
+                    # other additional GET arguments (like `form_data`, eg).
+                    key_args = list(args)
+                    key_kwargs = kwargs.copy()
+                    key_kwargs.update(request.args)
+                    cache_key = wrapper.make_cache_key(f, *key_args, 
**key_kwargs)
+                    response = cache.get(cache_key)
+                except Exception:  # pylint: disable=broad-except
+                    if app.debug:
+                        raise
+                    logging.exception('Exception possibly due to cache 
backend.')
+
+            # if this is not a GET, or if no response was cached, compute the
+            # response using the wrapped function
+            if response is None:
 
 Review comment:
   But `response` could still be `None` in line 80, if it doesn't exist in the 
cache. In that case, we need to compute the response.

----------------------------------------------------------------
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]


With regards,
Apache Git Services

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

Reply via email to