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/03/18 16:12:26 UTC

[GitHub] [incubator-superset] betodealmeida commented on a change in pull request #7032: Fetch charts with GET to benefit from browser cache and conditional requests

betodealmeida commented on a change in pull request #7032: Fetch charts with GET to benefit from browser cache and conditional requests
URL: https://github.com/apache/incubator-superset/pull/7032#discussion_r266521308
 
 

 ##########
 File path: superset/utils/decorators.py
 ##########
 @@ -29,3 +35,51 @@ def stats_timing(stats_key, stats_logger):
         raise e
     finally:
         stats_logger.timing(stats_key, now_as_float() - start_ts)
+
+
+def etag_cache(max_age, check_perms=bool):
+    """
+    A decorator for caching views and handling etag conditional requests.
+
+    The decorator caches the response, returning headers for etag and last
+    modified. If the client makes a request that matches, the server will
+    return a "304 Not Mofified" status.
+
+    """
+    def decorator(f):
+        @wraps(f)
+        def wrapper(*args, **kwargs):
+            try:
+                check_perms(request)
+                # 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
 
 Review comment:
   Ah, good point. I'll do that.

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