Insert will overwrite an existing cached value with the same Key; Add fails (does nothing) if there is an existing cached value with the same key. So there's a case for saying you should always use Insert since the first time the code runs it will put your object into the cache and when it runs subsequently it will update the cached value.
You can use either Cache.Add() or Cache.Insert() methods for caching your data. The only difference between the two is, Cache.Add() method returns the object which you want to cache.
So let’s say if you want to use the object and cache it as well. You can do so in a single line of code with the help of Cache.Add().
Cache.Insert() methods has 4 different types of overloaded methods while Cache.Add() has only one.
Cache.Add()
also returns a cached object fromCache
after it was added:Insert
will overwrite an existing cached value with the same Key;Add
fails (does nothing) if there is an existing cached value with the same key. So there's a case for saying you should always use Insert since the first time the code runs it will put your object into the cache and when it runs subsequently it will update the cached value.You can use either
Cache.Add()
orCache.Insert()
methods for caching your data. The only difference between the two is,Cache.Add()
method returns the object which you want to cache. So let’s say if you want to use the object and cache it as well. You can do so in a single line of code with the help ofCache.Add()
.Cache.Insert()
methods has 4 different types of overloaded methods whileCache.Add()
has only one.