Export (0) Print
Expand All

ObjectCache.Add Method

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.

This member is overloaded. For complete information about this member, including syntax, usage, and examples, click a name in the overload list.

  Name Description
Public method Add(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.
Public method Add(String, Object, DateTimeOffset, String) When overridden in a derived class, inserts a cache entry into the cache without overwriting any existing cache entry.
Public method Add(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.
Top

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.

Show:
© 2014 Microsoft