2003-09-24

Been working on caching code for Oddmuse. Ordinarily, pages change even when their raw text does not. If a page A links to another page B, then the HTML of page A looks different depending on whether page B exists or not. The HTML of page A can change.

The file upload feature added something new, however. A page offering content A for download does not change when other pages change. In this case, caching makes sense. At the same time, the files are stored as MIME-encoded text, so preparing the file is also expensive, and downloading the file is probably slow, since files are often much larger than plain text. Caching these files is both possible and useful.

I implemented the approach of sending Last-Modified headers with the files, and when a visitor calls the download action without asking for any particular revision, and that visitor sends along an If-Modified-Since header, then – if the values of the Last-Modified and the If-Modified-Since header are the same, the status 304 Not Modified is returned.

Something doesn’t work, however. If you edit a picture page and upload a new picture, and save, then you end up at a redirect page, which redirects you to the page you edited. And when the page is rendered, the file data is translated into a img tag pointing to the same page but using the download action. Thus, the browser will (should) display the correct image – the new image. Not the old one.

Currently you have to reaload the page again after editing it, in order to refresh the images.