In normal Aspx. CSCodeYou can use:
Cache cache = new cache ();
However, in XXXX. CS, the following method cannot be used:
Never expire
Httpcontext. Current. cache. insert ("name", "Wang Xiang", null, datetime. maxvalue, timespan. Zero, cacheitempriority. notremovable, null );
Name: Key
Wang Xiang: Value
Null: indicates no cache dependency
Datetime. maxvalue: the maximum value of the time (9999-99-99 12:59:59), indicating that the absolute time expiration policy is not used.
Timespan. Zero: indicates that smooth expiration is not used.
Cacheitemprority. notremovable: indicates that the priority is not to delete the cache.
Null: Not very useful. Just null
Absolute Time expired (automatically expired 10 seconds later)
Httpcontext. Current. cache. insert ("name", "Wang Xiang", null, datetime. Now. addseconds (10), timespan. Zero, cacheitempriority. notremovable, null );
Smooth expiration time (automatically expired if the cache is not accessed for 10 consecutive seconds)
Httpcontext. Current. cache. insert ("name", "Wang Xiang", null, datetime. maxvalue, timespan. fromseconds (10 ));
Cache update policy
If (httpcontext. Current. cache ["usercachelist"]! = NULL)
{< br> ht = (hashtable) httpcontext. current. cache ["usercachelist"];
ht. add (UID, httpcontext. current. cache ["user" + uid]);
}
Else
{
Ht. Add (UID, httpcontext. Current. cache ["user" + uid]);
// Httpcontext. Current. cache ["usercachelist"] = HT;
Httpcontext. Current. cache. insert ("usercachelist", HT, null, datetime. maxvalue, timespan. Zero, cacheitempriority. notremovable, null );
}