On Thu, 16 Nov 2000, Geoffrey Young wrote:
> it's the lack of a 304 that's bothering me (today :)
> 
> If I just put your lines into a handler I get this from netscape:
>   If-Modified-Since => Thu, 16 Nov 2000 12:48:04 GMT; length=1150
> 
> but, since there is no modification time for the 'document' to compare to
> locally, 
> my headers out are:
> 
>   Expires => Thu, 16 Nov 2000 12:56:45 GMT
>   Last-Modified => Thu, 16 Nov 2000 12:50:45 GMT
> 
> with status 200 since the document was (again) generated (with new headers).

Okay, so what you want is not to implement the headers but rather the
If-Modified handler.  My best advice is stay true to the laziness that led
us to Perl in the first place and just set up mod_proxy.  It will handle
this for you quite nicely.

If you really don't want to use a proxy server, the first step is to
handle the If-Modified-Since part, and your proposal for intercepting
those sounds fine.  You'd need to keep a database mapping URLs to last-mod
times and expiration times.  You'd look up the incoming URL, send back the
appropriate response it it's not modified and hasn't expired, and let it
pass through in all other cases.  Of course this is sort of lame because
if it's really good until the time in your Expires header you should be
caching it to hand out to other clients without re-generating.

To do a real caching scheme with good performance, I would propose this:
- Use URLs that map to real file names.
- Create your content generation handler as a 404-handler which gets
invoked when one of those files is not on disk.
- When you generate a page, send it to the client and then write it to
disk.
- Keep a little database of expiration times, which a cron job can use to
periodically delete expired pages.

This is the best possible performance you can get from a caching scheme,
since when things are cached they are served as static files and Apache
worries about the If-Modified stuff for you.

If you're paranoid about serving a page that has been expired for even a
second, you'll have to do something more complex with a TransHandler that
decides whether or not you can use the static file.  This will be a bit
slower.  I think AxKit does something along these lines, and you could
probably steal some code for it from there.

- Perrin

Reply via email to