Caching troubles

I’m stumped; so this is a shout out to the lazy web.

For the some of the sites that I publish I load shift the bandwidth for serving images to another machine. I do this by having those site do a temporary redirect to images.redzephyr.net which serves the image from a cache. If it is not in it’s cache it pulls the image from the original server.

This scheme was working fine until image server was upgraded and moved it to a new IP address.

Since that change my the cache directory on the image server seems to slowly fill with images from which the first N bytes have been dropped. If I clear the cache the problem goes away for a while; but reemerges slowly but surely.

Meanwhile this is polluting the browser side caches of my users and I need a scheme to clear their caches. I have a lame scheme to do that (changing all the redirected URLs).

If anybody recognize what stupid thing I’ve overlooked?

ps. How to “Bypass your browser’s cache“.

0 thoughts on “Caching troubles

  1. epc

    What sort of redirect are you issuing, 302 or 307?

    How are you ensuring that the image cache server doesn’t get redirected back to itself (checking for its IP? Could it be connecting from a different IP than you expect?)

    Is “N” at all consistent? Does “N” match any other byte sizes, eg the length of the file’s URL?

  2. Julius Davies

    Maybe try ditching the image server altogether? I find judicious use of HTTP’s “last-modified” and “expires” headers (along with the subsequent “if-modified-since”) on all my images does wonders. You’re forcing the browser to establish a new connection to a different site for the images; doesn’t that hurt HTTP keepalive and all that HTTP request pipelining stuff? Nevermind the time it takes for the DNS lookup!

    Two tangential thoughts:
    (I suspect that since you’re a committer on Apache’s “httpd” project you’re probably familiar with these tricks.)

    (Jason Hunter has a nice presentation on this stuff: http://developers.sun.com/learning/javaoneonline/2006/webtier/TS-4251.html [requires free Sun Developer Network Login])

    The server’s only power over the browser’s cache is the ability to change the URL. To force the browser to stop using its cached copy, change the URL of the file so that the browser thinks it’s a completely different resource. Just like you’re doing.

Leave a Reply

Your email address will not be published. Required fields are marked *