avoid rendering documents with an external cache
There are several headers that will let external caches avoid retrieving a page from your server. To use headers that set expiration dates, like Expires and Cache-Control, you need to be able to know the earliest date that a page will change.
A cache can send an If-Modified-Since header with a date along with a request to indicate the date of it's cached page. The server can return a 304 status message instead of the content to signify that the page has not been modified. This fragment, modified from ImageFile.py, sends that response if the date is earlier than a given date:
def checkNotMod(self, modDate, REQUEST, RESPONSE): """ If REQUEST contains an If-Modifed-Since header, and modDate is not after that date, set the appropriate status on RESPONSE and return true, else return None. """ # ripped from ImageFile.py header=REQUEST.get_header('If-Modified-Since', None) if header is not None: header=string.split(header, ';') # Some proxies seem to send invalid date strings for this # header. If the date string is not valid, we ignore it # rather than raise an error to be generally consistent # with common servers such as Apache (which can usually # understand the screwy date string as a lucky side effect # of the way they parse it). try: mod_since = DateTime(header) except: mod_since = None if mod_since is not None and modDate <= mod_since: RESPONSE.setStatus(304) return 1 return None
Another way to help a cache is to send an ETag header for every unique piece of content. The WebDAV code in the Zope source tree currently has some classes to help with this.