Cache Usage: records when the cache is removed

Source: Internet
Author: User
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;
}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.