The 'Expires:' HTTP header tells a client how long it may cache a response for an URL before it should try asking the source of the URL for a new copy. Proxies also use the expiration date to determine how long they may return a cached response to their clients that are asking for new data.
There are two methods of calculating the expiration date of a response. It can be calculated based on the time the server received the request or can be calculated based on the time the content was last modified. We call these the 'req' response lifetime and 'mtime' lifetime, respectively.
These times are specified in a separate <expiry> section of the configuration file. This section applies to all the virtuals in phhttpd. Lets look at an example. This has phhttpd telling the client to cache files ending in ".html" for 10 minutes after the request was made, or 1 minute after the content was last modified, which ever is later.
<expiry> <regex req="600" mtime="60">.*.html< /> <regex req="300" mtime="30">.*.gif< /> <default req="300" mtime="30" /> </expiry> |
".gif" graphics are cached for half as long, as are all remaining document types. The regular expressions here are POSIX regular expressions, as described in 'regex(7)'.
When a response is generated, phhttpd checks all the expiry regular expressions to see if any match the filename. The first that matches, in config file order, will be used. If no regular expressions match and default lifetimes were given in the config file, these will be used. An 'Expires:' header will only be generated if lifetime information was attached to the response's filename through the above methods.
Using regexps to specify cache lifetimes does add some processing latency to content generation, but the result of the regexp matching will be cached and stored in the response cache. As long as the document remains in the response cache, it will retain the cached lifetime values.