I don't know all about caching, but here are some tips:
Anon # 1,2: (static, semi-dynamic elements) You can set them to never end. If you need to change them, change their URL. If-modified, because checks are cheap, but not free.
Anon # 3: (dynamic elements) Here, where ETags and / or Last-Modified are very convenient. Depending on what you service, you can create a good Last-Modified header. If your database stores the modified date of all the items you planned to show, you can do something with the result of SELECT MAX(last_updated) FROM items_to_show . Caveat: This takes into account the age of the data, not the age of your template, so if you changed your django, you donβt understand how to report that in the header.
Or you can do something similar with ETag. This may be a checksum of the content that is generated. This will take into account the template change.
Something to consider with both of these approaches to caching dynamic content is that they really save more bandwidth than downloading server / database on the Internet. You can always use Expires wisely, however, to help in cases where the changes on the page are periodic and predictable.
My login suggestions would be similar, but I would look at the Vary header. This may signal caching of proxy servers that different registered users will not serve the same content.
In general, I would use either ETag or Last-modified, but not both.
user37078
source share