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/19 18:02:46 UTC

[GitHub] [incubator-superset] betodealmeida commented on a change in pull request #7319: Cache invalidation

betodealmeida commented on a change in pull request #7319: Cache invalidation
URL: https://github.com/apache/incubator-superset/pull/7319#discussion_r277052156
 
 

 ##########
 File path: superset/assets/src/chart/chartAction.js
 ##########
 @@ -239,6 +239,25 @@ export function exploreJSON(formData, force = false, timeout = 60, key, method)
 
     const annotationLayers = formData.annotation_layers || [];
 
+    // clear cache on POST; this happens in Explore view when "Run Query" is
+    // clicked, or in the dashboard when force refresh is clicked
+    if (method === 'POST' && 'caches' in self) {
+      caches.open(CACHE_KEY).then(supersetCache =>
+        supersetCache
+          .keys()
 
 Review comment:
   `keys` are all the URLs stored in the cache.
   
   Let's say you visited a dashboard that has a chart `1` and an extra filter `name=dave`. Your browser cache would look somewhat like this (using a pseudo-URL):
   
   ```javascript
   cache = {
     'http://example.com/?slice_id=1&name=dave': Response(...),
   }
   ```
   
   Now you go to the Explore view for that chart. When the page loads, it will do a `GET` and cache the request, so now your cache looks like this:
   
   ```javascript
   cache = {
     'http://example.com/?slice_id=1&name=dave': Response(...),
     'http://example.com/?slice_id=1': Response(...),
   }
   ```
   
   You decide to change some parameters in chart `1`. You click "Run query", which does a `POST` request. You save the chart.
   
   **Without cache invalidation**, the following would happen:
   
   1. You visit the dashboard again. You notice the chart is different than what you saved, because you're seeing the cached version.
   2. You click "Force refresh". This does a `POST` request, and you see the new chart. You're happy.
   3. You visit the dashboard again in the same day, before the cache expiration. You see the old chart again, because it's still cached in the browser and in the server. You're confused and sad.
   
   **With cache invalidation**, the following will happen:
   
   1. You click "Run query" while exploring chart `1`.
   2. This invalidates all the responses stored **on the client** that reference that chart. This means your browser cache would now be empty.
   3. **On the server side** we can't iterate over keys, so only the `http://example.com/?slice_id=1` response would be invalidated.
   4. You save the chart.
   5. You visit the dashboard again. The browser cache is empty, so it does a `GET` request for chart `1` with the extra filter (`http://example.com/?slice_id=1&name=dave`).
   6. This is a cache hit on the server, so it returns old data.
   7. You click "Force refresh". This does a `POST` request, which returns the new chart and invalidates `http://example.com/?slice_id=1&name=dave` in the server. You're happy.
   8. You visit the dashboard again in the same day, before the cache expiration. The browser does a `GET` request, misses caches, and shows the new chart. You're happy, and everything is cached now, both on the server and on the client.

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