how clear client cached images embedded in Web feed items being updated

742 views Asked by At

I am publishing Web Feeds containing charts embedded in the feed items in form of pictures and returned to the client polling the web feed using a MVC action, /RSS_Img/filename.

Some of the charts get updated together with the feed item and I'd like to have the client re-load the image once it has been modified at server side (I can control when the chart is updated as this is performed by another controller's action).

At the same time, I do not want to avoid caching on the client side as this would hit me back with an impressive increase of bandwidth.

What are my best options? I have considered the following:

  • obviously change the image name - but it is not acceptable as it would break the feed items which might be forwarded as mail items - or greatly increase storage size in case I keep the old version
  • mapping what are the syndication items which potentially might be updated, and in the action retrieving the image, setting Response.Cache.SetCacheability(HttpCacheability.Server); just for those items [actually I think I should put cacheability to none as I guess there is little advantage in caching the result of the RSS_Img action: it basically just load and return the file itself.].
    This would require that I retrieve the id of the images subject to refreshing (or frozen) from a SQL server (I'm handling a great quantitiy of chart images), which will add a considerable burden on the WebApp.
    Moreover, I cannot be always sure what are the items potentially being updated, so this approach is not covering 100% the requirement.

The solution I was looking for was finding a simple way to invalidate the cache as I alter the image file - I can easily use something like HttpResponse.RemoveOutputCacheItem("/RSS_Img/" + fileName.Value): but this seems to affect only the server cache.

I do not have other options coming to my mind, any other practical approach?

1

There are 1 answers

3
Jeremy Stein On

The traditional solution is to reference the image with a dummy parameter like <img src="chart.gif?cache=448267163"/>. Whenever you update the chart, update the links to it with a new value. Often the date of the last update is used as the parameter value.