#32531: Cache key not learnt for 304 responses — view must keep redoing work 
until
"fresh" request comes in!
----------------------------------------------+------------------------
               Reporter:  Nathan Vander Wilt  |          Owner:  nobody
                   Type:  Uncategorized       |         Status:  new
              Component:  HTTP handling       |        Version:  3.1
               Severity:  Normal              |       Keywords:
           Triage Stage:  Unreviewed          |      Has patch:  0
    Needs documentation:  0                   |    Needs tests:  0
Patch needs improvement:  0                   |  Easy pickings:  0
                  UI/UX:  0                   |
----------------------------------------------+------------------------
 Discovered an interesting situation that's easy to hit in a development
 environment but might result in some wasted work in a production setting
 too. Consider this situation:

 * I load a Django-rendered page in my browser. This browser keeps its own
 cache of the rendered response and its ETag.
 * The Django cache on the serverside gets flushed somehow (e.g. if it's a
 `LocMemCache` and I'm using `runserver` this happens whenever I touch a
 file…)
 * Now I (gently) referesh the page in my browser and it sends a request
 with `If-None-Match` and the ETag that it knows for the page.
 * Since the cache was flushed the view has to render the page again. In
 this scenario the page hasn't changed, so after the render happens, the
 ETag matches — hooray! The browser gets a 304 Not Modified response back.

 But here's the problem: the next time I gently refresh the browser (i.e.
 allow it to use its usual caching) the last step is repeated in whole!
 That is, the view can end up rendering the page AGAIN and AGAIN and each
 time the ETag matches in the end but Django does not seem to remember
 that.

 I suspect that the culprit might be related to the logic in
 `UpdateCacheMiddleware.process_response` which will only call
 `learn_cache_key` when the `response.status_code == 200`?

-- 
Ticket URL: <https://code.djangoproject.com/ticket/32531>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

-- 
You received this message because you are subscribed to the Google Groups 
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-updates/049.7a8059a40c0ae35efee14074304c8d2b%40djangoproject.com.

Reply via email to