using cache technology to accelerate your web 1
asp.net CacheDependency
with asp.net 2.0, you can use cache mechanism to accelerate your web speed.
now, let's take a look at the cache with cachedependency of file.
source code is followed:
///code begin:
string content = this.Cache["content"] as string;
if(content == null)
{
Response.Write("load text from file.<br/>");
content = System.IO.File.ReadAllText(Server.MapPath("hello.txt"));
System.Web.Caching.CacheDependency dep = new System.Web.Caching.CacheDependency(Server.MapPath("hello.txt"));
Cache.Insert("content", content, dep);
}
Response.Write("the content of the file is:" + content);
///!~~ code end.
the content will be loaded from file,only the first time to visit the page after the text file has changed.
相关经验
- asp.net:在using语句中使用return语句!
- asp.net中 UrlEncode 的编码问题
- asp.net 设计模式之——单例模式
- Asp.net 2.0 关于Header/title/Meta tages/Style操作的一点小技巧
- templateEngine2 asp.net 开源模板引擎
- asp.net中的缓存机制(一):页面缓存
- 没有对“C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\Temporary ASP.NET Files”的写访问权限
- params关键字:参数数目可变
- 开源的asp.net wiki系统
- ASP.Net中的HttpHandler,自定义Http处理及应用的原理和实现方法