Reputation: 395
I've tried a lot of things, and they all failed. My Django (2.0) website has some pages which take a lot of time to generate. I want to keep this pages in the database cache of the Django server until the database changed. My goal:
The closest I got was to enable database caching, enabled per-site caching, and using cache.clear() on receiving post_save and post_delete signals. But still, if I pressed 'back' in my browser, the local cache was used (so no request was send to the server). I tried to fix this by adding @never_cache to the view, but this also prevented caching in the middleware...
Upvotes: 2
Views: 283
Reputation: 169
Hi,I encountered a similar situation, when I used cache_page in Django,
urlpatterns = [
path(
'xxx',
cache_page(
settings.CACHE_TTL, key_prefix='xxx'
)(xxx),
name='xxx'
),
]
it will add one response header in the response:
cache-control: max-age=600
Then the browser will not request new data even my cache data have changed in 10 minute.
My solution is change the response header at nginx:
location ~ (/xxx|/yyy) {
# ...
proxy_hide_header Cache-Control;
add_header Cache-Control no-store;
# ...
}
Upvotes: 1