superset-notifications mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From GitBox <...@apache.org>
Subject [GitHub] [incubator-superset] DiggidyDave 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:19:17 GMT
DiggidyDave 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_r266210326
 
 

 ##########
 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
+                logging.exception('Exception possibly due to cache backend.')
 
 Review comment:
   any chance you can tighten up this exception handling and messaging? Do we really need
to disable the linter here? If we handle distinct exception types could we get logging that
is more definitive than "possibly due to...."? likewise down on like 73.  Sorry to be a stickler,
but caching issues can be super frustrating, and this sort of thing can go a long way to short-circuiting
debugging work.
   
   Also, this is swallowing any info in the underlying exception/message, if we can get that
logged also it could be very helpful.

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