Book Image

Django 1.0 Template Development

Book Image

Django 1.0 Template Development

Overview of this book

Table of Contents (17 chapters)
Django 1.0 Template Development
Credits
About the Author
About the Reviewers
Preface
Index

Working with outside caches


Not every cache you'll deal with is stored locally on your server. For example, many web browsers have built-in functionality to cache content and some networks are behind proxies and web accelerators.

We can provide some additional information via HTTP headers to these caches that make sure our content is stored properly. Specifically, the Vary HTTP header allows us to tell a cache how to differentiate content that it might otherwise think is the same.

As a simple example, we can tell a cache to cache content that is based on the user agent that a visitor is using. This lets us cache a request for a mobile device, such as an iPhone, differently than we would for a generic mobile device.

from django.views.decorators.vary import vary_on_headers

@vary_on_headers('User-Agent')
def detail(request, pid):
    ...

If you'd like to try it out, you can do so if you have two web different web browsers. Point your first browser at the page and it will cache the content. Point...