ASP.NETキャッシュメカニズム

3485 ワード

一、ページレベルのキャッシュ
ページ上部の追加
10 , 。

BaryByParam , none, key , 。

, 10 。

Web.config ,system.web


      
      
        
          
        
      
    

, 。

, , 。

OutputCache , , , Cache ( IIS )。

 //       ,     object  
 string str = (string)HttpRuntime.Cache["nowTime"];
 //        
 if (String.IsNullOrEmpty(str))
 {
        //    
        str = DateTime.Now.ToString();
        //        
        //    :System.Web.Caching;
        //  1:         ,  2:           
        CacheDependency cdep = new CacheDependency(Server.MapPath("~/CacheRelyOn.txt"), DateTime.Now);
        //    
        //key ,value ,      
        Cache.Insert("nowTime", str, cdep);
}

, 。

, SQL , .Net Framewrok 4.0

1. cmd , “cd ..\..” C

2. “cd Windows\Microsoft.NET\Framework\v4.0.30319” , “aspnet_regsql.exe” 

3. :

aspnet_regsql.exe -S localhost -E -d -ed  -- windows

aspnet_regsql.exe -S localhost -U sa -P 123 -d -ed   --

4. :

aspnet_regsql.exe -S localhost -U sa -P 123 -d -t -et

5.Web.config , :


    
  
6.Web.config cache
    
      
        
            
        
      
    
7. ,
        //      
        string str = (string)HttpRuntime.Cache["nowTime"];
        //       
        if (String.IsNullOrEmpty(str))
        {
            //      
            str = DateTime.Now.ToString();
            //          
            AggregateCacheDependency acdep = new AggregateCacheDependency();
            //     ,  1:     caching   add   name ,  2:  
            acdep.Add(new SqlCacheDependency("sqlCache", "Student"));
            acdep.Add(new SqlCacheDependency("sqlCache", "Teacher"));
            //    
            Cache.Insert("nowTime", str, acdep);
        }