What are the differences between page. cache, httpcontext. cache, httpruntime. cache, and hashtable?

Source: Internet
Author: User
Code
Httpcontext. cache, httpruntime. cache. There is no difference in usage, that is, the scope of use is different.
Httpcontext. cache is context-based and can be used for the same user. If an access is changed, the cache cannot be used.
Httpruntime. cache is global and can be accessed by task users as long as there is content.

3 wind code
Public   Class Httpruntimecache
{

Public   Static   String Instance ()
{
String VC = ( String ) Httpruntime. cache [ " Test " ];
If (VC = Null )
{
Httpruntime. cache. Add ( " Test " , " Test " , Null , System. datetime. Now. adddays ( 10 ), Timespan. Zero,
Cacheitempriority. Default, Null );
}
Return VC;
}

}

Page. cache is actually an interface to access other caches. You can access httpcontext. cache and httpruntime. cache through page. cache.

Another way to save the cache is to use hashtable to save it. The value indicates that the cache is global and cannot expire. I think this is the same as httpruntime. what is the difference between cache. I have not verified the security performance. hashtable can be stored in a special way, that is, the synchronous token should be used for new.

3 wind code
Public ClassHashcache
{
Private StaticHashtable parmcache=Hashtable. synchronized (NewHashtable ());

Public static void cacheparameters ( string cachekey, string interval parms)
{< br> parmcache [cachekey] = partition parms;
}

Public Static StringGetcachedparameters (StringCachekey)
{
Return(String) Parmcache [cachekey];
}
}

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.