When and How is an image cached for an ASPX with ContentType = image/jpeg ?

Posted by Aamir Hasan on ASP.net Weblogs See other posts from ASP.net Weblogs or by Aamir Hasan
Published on Sun, 18 Apr 2010 05:17:00 GMT Indexed on 2010/04/18 5:23 UTC
Read the original article Hit count: 197

Filed under:
|

 In asp.net you can cache your page. You can vary the output cache by the following

  1. The query string in an initial request (HTTP GET).
  2. Control values passed on postback (HTTP POST values).
  3. The HTTP headers passed with a request.
  4. The major version number of the browser making the request.

      A custom string in the page. In that case, you create custom code in the Global.asax file to specify the page's caching behavior.

Link: http://msdn2.microsoft.com/en-us/library/xadzbzd6(VS.80).aspx


you can set the output caching for your GetImage.aspx, so that you dont have to requery the database every image request ,
but you must use varybyParam , so that you have a cached version for every parameters arrangement:
set the output cache for your page like this :
At top of ASPX page:

<%@ OutputCache Duration="600" VaryByParam="ID,Height,Width" %>

VaryByParam  attribute allows you to vary the cached output depending on the query string.
Adding this will make your images cached for 600 seconds, so that if the image request within this period ,the cahed version will be returned

© ASP.net Weblogs or respective owner

Related posts about ASP.NET

Related posts about cache