Search code examples
imageresizerimageresizer-diskcache

is it possible to invalidate cache of a specific image using ImageResizer?


I am using ImageResizer (http://imageresizing.net/) and was curious if anyone has found a way to clear the cache for a particular item?

This would help me out greatly as I have some legacy systems that need to get updated images and I cannot add any query string parameters to the to images to refresh the cache.


Solution

  • In order to scale to millions of items, DiskCache does not maintain a cross-reference table between source files and cached images - it instead uses a one-way hash function that combines the source file, modified date, and commands.

    If you want to do invalidation, your provider needs to support it via IVirtualFileWithModifiedDate. There is a cost associated with invalidation checks on every request, so some form of windowed caching is suggested.

    You can also use URL rewriting to map "legacy URLs" to new immutable urls. For small numbers of images, this is the most performant approach. Keep in mind that even if ImageResizer is serving the right image, there are other layers of caching (browser, proxy, etc) that will get in the way.