(一)、在ASP.NET 2.0 中增加了缓存技术 ,不尽可以支持1.x的模式,如:
<%@ OutputCache Duration="60" VaryByParam="None" Location=“Any” %>
其中“Location”可以是:Any / Client / DownStream / Server / ServerAndClient / None
(二)、还支持缓存配置,在Web.config中定义如:







在页面中引用某项缓存配置:
<%@ OutputCache CacheProfile="Cache30Seconds" %>
(三)、也可以通过代码方式设置缓存性:
Response.Cache.SetCacheability(HttpCacheability.Public);
其中“Public”对应“Any”、“Private”对应“Client”等。
(四)、文件依赖缓存:
通过 Response.AddFileDependencyPath / AddFileDependencies 将某个文件的(绝对)路径添加为缓存失效的判断条件,如:










(五)、数据表依赖缓存
1.为SQL Server 启用缓存通知
C:/WINDOWS/Microsoft.NET/Framework/v2.0.40217
aspnet_regsql.exe -S <Server> -U <Username> -P <Password> -ed -d Northwind -et -t Employees
2.为缓存功能配置网页
<%@ OutputCache Duration="3600" SqlDependency="Northwind:Employees" VaryByParam="n
3.在Web.config 文件中设置缓存配置







(六)、浏览器不同缓存不同版本
<%@ OutputCache Duration="10" VaryByParam="None" VaryByCustom="browser" %>
Response.Cache.SetExpires(DateTime.Now.AddMinutes(1d));
Response.Cache.SetCacheability(HttpCacheability.Public);
Response.Cache.SetValidUntilExpires(true);
Response.Cache.SetVaryByCustom("browser");
(七)、使用参数缓存不同版本
<%@ OutputCache Duration="60" VaryByParam="City" %>
Response.Cache.SetExpires(DateTime.Now.AddMinutes(1.0));
Response.Cache.SetCacheability(HttpCacheability.Public);
Response.Cache.SetValidUntilExpires(true);
Response.Cache.VaryByParams["Zip"] = true;
(八)、使用Substitution控件 实现在缓存页面中局部不缓存
(九)、应用程序缓存
Cache.Insert("CacheItem2", "Cached Item 2");
string[] dependencies = { "CacheItem2" };
Cache.Insert("CacheItem3", "Cached Item 3", new System.Web.Caching.CacheDependency(null, dependencies));
Cache.Insert("CacheItem4", "Cached Item 4", new System.Web.Caching.CacheDependency(Server.MapPath("XMLFile1.xml")));
System.Web.Caching.CacheDependency dep1 = new System.Web.Caching.CacheDependency(Server.MapPath("XMLFile.xml"));
string[] keyDependencies2 = { "CacheItem1" };
System.Web.Caching.CacheDependency dep2 = new System.Web.Caching.CacheDependency(null, keyDependencies2);
System.Web.Caching.AggregateCacheDependency aggDep = new System.Web.Caching.AggregateCacheDependency();
aggDep.Add(dep1);
aggDep.Add(dep2);
Cache.Insert("CacheItem5", "Cached Item 5", aggDep);