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];
}
}