Edit

ObjectCache Class

Definition

Represents an object cache and provides the base methods and properties for accessing the object cache.

public ref class ObjectCache abstract : System::Collections::Generic::IEnumerable<System::Collections::Generic::KeyValuePair<System::String ^, System::Object ^>>
public abstract class ObjectCache : System.Collections.Generic.IEnumerable<System.Collections.Generic.KeyValuePair<string,object>>
type ObjectCache = class
    interface seq<KeyValuePair<string, obj>>
    interface IEnumerable
Public MustInherit Class ObjectCache
Implements IEnumerable(Of KeyValuePair(Of String, Object))
Inheritance
ObjectCache
Derived
Implements

Remarks

The ObjectCache type is the primary type for the in-memory object cache. To develop a custom cache implementation, you derive from the ObjectCache class.

Note

The ObjectCache class is new as of the .NET Framework 4.

The built-in MemoryCache class derives from the ObjectCache class. The MemoryCache class is the only concrete object cache implementation in the .NET Framework 4 that derives from the ObjectCache class.

Notes to Implementers

Because the ObjectCache type represents only common cache functions, there is no requirement for how an ObjectCache instance must be instantiated and obtained. In addition, there is no requirement that concrete implementations of the ObjectCache class must be singletons.

Note: MemoryCache is not a singleton, but you should create only a few or potentially only one MemoryCache instance and code that caches items should use those instances.

When you inherit from the ObjectCache class, you must override its methods.

Constructors

Name Description
ObjectCache()

Called from constructors in derived classes in order to initialize the ObjectCache class.

Fields

Name Description
InfiniteAbsoluteExpiration

Gets a value that indicates that a cache entry has no absolute expiration.

NoSlidingExpiration

Indicates that a cache entry has no sliding expiration time.

Properties

Name Description
DefaultCacheCapabilities

When overridden in a derived class, gets a description of the features that a cache implementation provides.

Host

Gets or sets a reference to a managed hosting environment that is available to ObjectCache implementations and that can provide host-specific services to ObjectCache implementations.

Item[String]

Gets or sets the default indexer for the ObjectCache class.

Name

Gets the name of a specific ObjectCache instance.

Methods

Name Description
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.

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.

Add(String, Object, DateTimeOffset, String)

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

AddOrGetExisting(CacheItem, CacheItemPolicy)

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

AddOrGetExisting(String, Object, CacheItemPolicy, String)

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

AddOrGetExisting(String, Object, DateTimeOffset, String)

When overridden in a derived class, inserts a cache entry into the cache, by using a key, an object for the cache entry, an absolute expiration value, and an optional region to add the cache into.

Contains(String, String)

When overridden in a derived class, checks whether the cache entry already exists in the cache.

CreateCacheEntryChangeMonitor(IEnumerable<String>, String)

When overridden in a derived class, creates a CacheEntryChangeMonitor object that can trigger events in response to changes to specified cache entries.

Get(String, String)

When overridden in a derived class, gets the specified cache entry from the cache as an object.

GetCacheItem(String, String)

When overridden in a derived class, gets the specified cache entry from the cache as a CacheItem instance.

GetCount(String)

When overridden in a derived class, gets the total number of cache entries in the cache.

GetEnumerator()

When overridden in a derived class, creates an enumerator that can be used to iterate through a collection of cache entries.

GetValues(IEnumerable<String>, String)

When overridden in a derived class, gets a set of cache entries that correspond to the specified keys.

GetValues(String, String[])

Gets a set of cache entries that correspond to the specified keys.

Remove(String, String)

When overridden in a derived class, removes the cache entry from the cache.

Set(CacheItem, CacheItemPolicy)

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

Set(String, Object, CacheItemPolicy, String)

When overridden in a derived class, inserts a cache entry into the cache.

Set(String, Object, DateTimeOffset, String)

When overridden in a derived class, inserts a cache entry into the cache, specifying time-based expiration details.

Explicit Interface Implementations

Name Description
IEnumerable.GetEnumerator()

Supports iteration over a generic collection.

IEnumerable<KeyValuePair<String,Object>>.GetEnumerator()

Supports iteration over a strongly typed collection.

Extension Methods

Name Description
ToAsyncEnumerable<TSource>(IEnumerable<TSource>)

Creates a new IAsyncEnumerable<T> that iterates through source.

ToFrozenDictionary<TSource,TKey,TElement>(IEnumerable<TSource>, Func<TSource,TKey>, Func<TSource,TElement>, IEqualityComparer<TKey>)

Creates a FrozenDictionary<TKey,TValue> from an IEnumerable<T> according to specified key selector and element selector functions.

ToFrozenDictionary<TSource,TKey>(IEnumerable<TSource>, Func<TSource,TKey>, IEqualityComparer<TKey>)

Creates a FrozenDictionary<TKey,TValue> from an IEnumerable<T> according to specified key selector function.

ToFrozenSet<T>(IEnumerable<T>, IEqualityComparer<T>)

Creates a FrozenSet<T> with the specified values.

ToImmutableArray<TSource>(IEnumerable<TSource>)

Creates an immutable array from the specified collection.

ToImmutableDictionary<TSource,TKey,TValue>(IEnumerable<TSource>, Func<TSource,TKey>, Func<TSource,TValue>, IEqualityComparer<TKey>, IEqualityComparer<TValue>)

Enumerates and transforms a sequence, and produces an immutable dictionary of its contents by using the specified key and value comparers.

ToImmutableDictionary<TSource,TKey,TValue>(IEnumerable<TSource>, Func<TSource,TKey>, Func<TSource,TValue>, IEqualityComparer<TKey>)

Enumerates and transforms a sequence, and produces an immutable dictionary of its contents by using the specified key comparer.

ToImmutableDictionary<TSource,TKey,TValue>(IEnumerable<TSource>, Func<TSource,TKey>, Func<TSource,TValue>)

Enumerates and transforms a sequence, and produces an immutable dictionary of its contents.

ToImmutableDictionary<TSource,TKey>(IEnumerable<TSource>, Func<TSource,TKey>, IEqualityComparer<TKey>)

Constructs an immutable dictionary based on some transformation of a sequence.

ToImmutableDictionary<TSource,TKey>(IEnumerable<TSource>, Func<TSource,TKey>)

Constructs an immutable dictionary from an existing collection of elements, applying a transformation function to the source keys.

ToImmutableHashSet<TSource>(IEnumerable<TSource>, IEqualityComparer<TSource>)

Enumerates a sequence, produces an immutable hash set of its contents, and uses the specified equality comparer for the set type.

ToImmutableHashSet<TSource>(IEnumerable<TSource>)

Enumerates a sequence and produces an immutable hash set of its contents.

ToImmutableList<TSource>(IEnumerable<TSource>)

Enumerates a sequence and produces an immutable list of its contents.

ToImmutableSortedDictionary<TSource,TKey,TValue>(IEnumerable<TSource>, Func<TSource,TKey>, Func<TSource,TValue>, IComparer<TKey>, IEqualityComparer<TValue>)

Enumerates and transforms a sequence, and produces an immutable sorted dictionary of its contents by using the specified key and value comparers.

ToImmutableSortedDictionary<TSource,TKey,TValue>(IEnumerable<TSource>, Func<TSource,TKey>, Func<TSource,TValue>, IComparer<TKey>)

Enumerates and transforms a sequence, and produces an immutable sorted dictionary of its contents by using the specified key comparer.

ToImmutableSortedDictionary<TSource,TKey,TValue>(IEnumerable<TSource>, Func<TSource,TKey>, Func<TSource,TValue>)

Enumerates and transforms a sequence, and produces an immutable sorted dictionary of its contents.

ToImmutableSortedSet<TSource>(IEnumerable<TSource>, IComparer<TSource>)

Enumerates a sequence, produces an immutable sorted set of its contents, and uses the specified comparer.

ToImmutableSortedSet<TSource>(IEnumerable<TSource>)

Enumerates a sequence and produces an immutable sorted set of its contents.

Applies to

Thread Safety

This type is thread safe.