很高兴今天学了点新东西,关于Cache

代码
private  System.Web.Caching.CacheItemRemovedCallback cacheCallBack; // 先声明一个删除缓存的委托
cacheCallBack  =   new  System.Web.Caching.CacheItemRemovedCallback(CacheDelete);
// 将委托和函数CacheDelete绑定

  CacheDelete(cacheKey, count, CacheItemRemovedReason.Underused);
// 手动调用删除函数cacheCallBack,Underused的表示这是我手动调用函数删除

   
Cache.Insert(cacheKey, count.ToString(), 
null , DateTime.Now.AddSeconds( 5 ), System.Web.Caching.Cache.NoSlidingExpiration, System.Web.Caching.CacheItemPriority.Low, cacheCallBack);
// 五分钟过期自动删除缓存与调用cacheCallBack


    
private   void  CacheDelete( string  cacheKey,  object  value, System.Web.Caching.CacheItemRemovedReason e)
    {
        
if  ( e  ==  System.Web.Caching.CacheItemRemovedReason.Expired  ||  
        e 
==  System.Web.Caching.CacheItemRemovedReason.Underused
      ){ }
    }

 

---------------------------------上面是c#的,又学了点基于JQ的CAHCE知识,就不开新文章了

 删除JQ的缓存  delete jQuery.cache[id][name];

 增加JQ的缓存  

 jQuery.cache[id] = {};

jQuery.cache[id][name] = data;

 

缓存的数据结构

var cache= 
{
    
"id1"
    {
        
"name""wsenmin",
        
"phone""110"
    },
    
"id2"
    {
        
"name""fuMing",
        
"age"19

    }
};

 

---------------------------------------------------------------

 

代码
< html >
< head  runat ="server" >
    
< title > Cache-缓存操作 </ title >   
    
< script  src ="Scripts/jquery-1.3.2-vsdoc.js"  type ="text/javascript" ></ script >
    
< script  type ="text/ecmascript" >
        jQuery(document).ready(
function () {
            jQuery.cache[
' me ' =  {};
            jQuery.cache[
' me ' ][ ' name ' =   ' wsenmin ' ;
            alert(jQuery.cache[
' me ' ][ ' name ' ]);
            
delete  jQuery.cache[ ' me ' ][ ' name ' ];
            alert(jQuery.cache[
' me ' ][ ' name ' ]);
        }); 
    
</ script >
</ head >
< body >
    
< form  id ="form1"  runat ="server" >
    
< div >  
    
</ div >
    
</ form >
</ body >
</ html >

 

 

 

你可能感兴趣的:(cache)