Welcome! Log In Create A New Profile


Custom App-Controlled Cacher

Posted by Lady Serena 
Custom App-Controlled Cacher
June 07, 2009 02:35PM
I have an application-controlled cache I would like nginx to take advantage of. The bonus of this cache is its use (via a HEAD method request) reduces the workload on my application server due to the script's termination right after getting the custom cache headers out while the request method is HEAD.

The application performs its own caching for this, but it would also be nice if nginx could perform the data caching as well to reduce the overall workload on the application server.

The two custom headers I have are: X-Avatar-Cache-ID, and X-Avatar-Time

X-Avatar-Cache-ID is used to uniquely identify an avatar image, since (depending on the request parameters and user's profile settings) each person's avatars may have one of 6 possible unique images available in 3 possible outputs (PNG, GIF, JPEG) for a total of 18 possible unique outputs. All of them need to be cached the exact same way, the application itself is designed to handle this so it works quite well.

X-Avatar-Time is the timestamp the application uses for its internal caching strategy, stored in the database along with the images, and is updated when someone updates their avatar, so the app's local-disk cache remains in-sync automagically across multiple FastCGI servers. This is the timestamp nginx needs to use to determine if it should a second request to the app server for the new image or just serve up a cached copy.

How would I go about setting up nginx to make an initial request to the FastCGI host to get these headers via HEAD, determine if it should serve up a locally cached copy or fetch the new copy with a regular GET, update its cached copy if needed, and send the image back to the client?

Example headers from real avatar image:
[jlhawkwell@Cougar:~] curl -I http://varusonline.com/avatars/2.png
HTTP/1.1 200 OK
Server: nginx/0.6.36
Date: Sun, 07 Jun 2009 18:19:33 GMT
Content-Type: text/html; charset=utf-8
Transfer-Encoding: chunked
Connection: keep-alive
X-Avatar-Modes: nhWp
X-Avatar-Cache-ID: 2-nhWp
X-Avatar-Time: 1243312376

Sorry, only registered users may post in this forum.

Click here to login

Online Users

Guests: 173
Record Number of Users: 8 on April 13, 2023
Record Number of Guests: 421 on December 02, 2018
Powered by nginx      Powered by FreeBSD      PHP Powered      Powered by MariaDB      ipv6 ready