您现在的位置:龙卷风首页 ›› 网络编程 ›› 阅读文章

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.

作者 不见不散 本文仅代表作者观点,与龙卷风资讯网立场无关。

我来说两句

内容/Content