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 2019/04/05 18:58:40 UTC

[GitHub] [incubator-superset] betodealmeida commented on a change in pull request #7227: Improve cache

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

 ##########
 File path: superset/utils/decorators.py
 ##########
 @@ -61,32 +62,49 @@ 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':
-                response = f(*args, **kwargs)
-                response.cache_control.public = True
-                response.last_modified = datetime.utcnow()
-                expiration = max_age if max_age != 0 else FAR_FUTURE
-                response.expires = response.last_modified + timedelta(seconds=expiration)
-                response.add_etag()
+            response = None
+
+            # if this is a GET request and we have a cache, try to fetch a
+            # cached response object
+            if cache and request.method == 'GET':
                 try:
-                    cache.set(cache_key, response, timeout=max_age)
+                    # 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:
+                response = f(*args, **kwargs)
+
+                # if this was a GET request, add headers that help with
+                # caching: Last Modified, Expires and ETag
+                if request.method == 'GET':
 
 Review comment:
   @DiggidyDave for `POST` requests we use the dataframe cache (key: is SQL query, value is dataframe).

----------------------------------------------------------------
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:
users@infra.apache.org


With regards,
Apache Git Services

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