superset-notifications mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From GitBox <...@apache.org>
Subject [GitHub] [incubator-superset] john-bodley commented on a change in pull request #7032: Fetch charts with GET to benefit from browser cache and conditional requests
Date Sat, 16 Mar 2019 18:40:07 GMT
john-bodley 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_r266210978
 
 

 ##########
 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:
   Maybe there is merit in following the pattern in Flask-Caching per [here](https://github.com/sh4nks/flask-caching/blob/master/flask_caching/__init__.py#L403)
where the error is re-raised in debug mode.

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


Mime
View raw message