In some cases, we need to know the cache update frequency. Therefore, we need to explore cache-related events (cacheitemremovecallback ). The following is an example: Page code Const String Key = " Anystringtest " ;
Const String Path = @" /Csdata/siteuser. xml " ;
Private Void BIND (){
System. Web. caching. cache ocache = Httpruntime. cache;
Siteuser user = Ocache. Get (key) As Siteuser;
If (User = Null )
{
User = New Siteuser ();
User = User. deserializefromxml ( Typeof (Siteuser), server. mappath (PATH )) As Siteuser;
Cachedependency depend = New Cachedependency (
Server. mappath (PATH ));
Timespan TS = Timespan. zero;
Ocache. insert (Key, user, depend,
Datetime. Now. addminutes ( 3 ), Ts, cacheitempriority. Default,
/* * *** Use anonymous delegation **** */
( String Key, Object OBJ, cacheitemremovedreason reason) => {
String Content = String . Format ( " {0}-Cache removal. Key = {1} \ r \ n " ,
Datetime. Now, key );
File. Write (server. mappath ( " /Csdata/log.txt " ), Content );
}
);
Lbldata. Text = " From Cache " ;
}
Lbluser. Text=User. Nickname;
}