Image caching on Client Side
I'm having a http handler that is retrieving images from the file system on the server. I need to cache these images on the client side(browser). For that thing i'm doing the following code
context.Response.Clear()
context.Response.ClearHeaders()
context.Response.ClearContent()
Dim ImageCacheExpiry = ConfigurationManager.AppSettings("ImageCacheExpiryDuration")
context.Response.Cache.SetCacheability(HttpCacheability.Private)
context.Response.Cache.SetExpires(DateTime.Now.AddHours(ImageCacheExpiry))
context.Response.Cache.VaryByParams(DisplayImage.FileName) = True
context.Response.Cache.SetLastModified(DisplayImage.DateModified)
context.Response.AddHeader("Content-Disposition", "inline; filename=" & DisplayImage.FileName)
contex开发者_StackOverflow社区t.Response.ContentType = DisplayImage.MimeType
context.Response.BinaryWrite(DisplayImage.ImageBytes)
context.Response.Flush()
context.Response.Close()
context.Response.End()
'DisplayImage is the object that is having all the data of images like
'DisplayImage.Filename, DisplayImage.FilePathandName, DisplayImage.MimeType etc
The thing happening with this is ... When i switch between the tabs its taking it from the cache... but when i hit the browsers refresh button its again going to the file system on the server... Please tell me how to cache these images on the client side.
P.S: Cant do markup caching for all the pages im my application.
Thanks a lot in advance....
Depending on browser and browser settings, your browser might be sending an If-Modified-Since request to see if the cached data is stale. You shoudl use something like Fiddler to figure out exactly what your browser is sending (and your server returning). You may need to handle this, and return a 304 (not modified) header.
精彩评论