我有一个http处理程序从服务器上的文件系统检索图像。我需要在客户端(浏览器)缓存这些图像。对于那件事我做下面的代码客户端图像缓存
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)
context.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
这种情况发生的事情是...当我从它的缓存中把它的标签之间切换......但是当我击中了浏览器的刷新按钮,它的再次进入服务器上的文件系统......请告诉我如何在客户端缓存这些图像。
P.S:无法对我的应用程序中的所有页面进行标记缓存。
非常感谢提前....
这就是缓存在浏览器中工作的方式。当您在浏览器中刷新页面时,浏览器将忽略任何缓存数据并从服务器获取新数据。 – 2011-02-24 20:09:31
@Shiv库马尔 - 通常你必须按住CTRL键,然后按刷新浏览器忽略缓存。只需按刷新通常会导致外部文件来自缓存。 – 2011-02-24 21:39:12
@DanTup,“通常”是这里的关键词。刷新对于不同的浏览器意味着许多不同的事情尽管如此,问题在于行为与预期相同,您无法控制每个浏览器的实现细节,您也不应该设计依赖于此类系统的系统。 – 2011-02-25 03:19:37