ObjectCache.Add Method

.NET Framework (current version)
 

When overridden in a derived class, inserts a cache entry into the cache, without requiring that an existing cache entry with a matching key be returned.

Namespace:   System.Runtime.Caching
Assembly:  System.Runtime.Caching (in System.Runtime.Caching.dll)

NameDescription
System_CAPS_pubmethodAdd(CacheItem, CacheItemPolicy)

When overridden in a derived class, tries to insert a cache entry into the cache as a CacheItem instance, and adds details about how the entry should be evicted.

System_CAPS_pubmethodAdd(String, Object, CacheItemPolicy, String)

When overridden in a derived class, inserts a cache entry into the cache, specifying information about how the entry will be evicted.

System_CAPS_pubmethodAdd(String, Object, DateTimeOffset, String)

When overridden in a derived class, inserts a cache entry into the cache without overwriting any existing cache entry.

The Add method overloads try to insert a cache entry into the cache, without overwriting or removing an existing cache entry that has the same key. The cache entry can be a typed CacheItem object or a generic object.

The AddOrGetExisting method overloads and the Add method overloads have one significant difference. When these methods insert a cache entry, if a matching entry is found in the cache, the AddOrGetExisting method overloads return the existing cache entry, but the Add method overloads do not. Having these different method overloads enables callers to optimize their code based on whether they need the existing cache entry. In distributed caches, returning an existing value by using the AddOrGetExisting method might be more expensive than returning a Boolean value by using Add method.

Return to top
Show: