I hope this tip helps someone, as it took me quite a while to get this working successfully.
Simple Gallery uses a number of HttpHandlers to serve up images, in particular, resized images. The caching API in .NET allows you to cache an entire pages/handlers output and vary the cache by parameters. Now, I've used this API quite a bit before, but never for multiple parameters.
Caching by multiple parameters is a perfect solution for Simple Gallery, but took a little while to get the syntax correct, as the API isn't exactly a collection for adding parameters like I first thought.
The actual code is as follows:-
context.Response.Cache.SetExpires(DateTime.Now.AddDays(1)) context.Response.Cache.VaryByParams("FileName") = True context.Response.Cache.VaryByParams("HomeDirectory") = True context.Response.Cache.VaryByParams("Width") = True context.Response.Cache.VaryByParams("Height") = True
This will create cached instances of the handler's output on a page that is unique by the 4 parameters above. It seem to improve performance quite a bit, especially when using the higher quality compression that just got implemented. |