-
If I insert to Cache by assigning the value:
Cache[“key”] = value;
what’s the expiration time?
-
Removing the same value from Cache:
I want to check if the value is in Cache by
if(Cache["key"]!=null), is it better to remove it from Cache byCache.Remove("key")orCache["key"]=null?
— Edit —
After having tried Cache.Remove and Cache["key"]=null, DO NOT USE Cache["key"]=null, as it will throw exceptions when used in stress.
1
Cache["key"] = valueis equal toCache.Insert("key", value)MSDN Cache.Insert – method (String, Object):
2 It’s better to remove values from cache by Cache.Remove(“key”).
If you use
Cache["key"] = nullit’s equal toCache.Insert("key", null).Take a look at the
Cache.Insertimplementation:and
CacheInternal.DoInsert:Compare it to
Cache.Remove:CacheInternal.DoRemove:And finally
Cache.Remove("key")is much more readble thanCache["key"] = null