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 Inheritors

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.

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

ObjectCache()

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

Fields

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

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

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.

Equals(Object)

Determines whether the specified object is equal to the current object.

(Inherited from Object)
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.

GetHashCode()

Serves as the default hash function.

(Inherited from Object)
GetType()

Gets the Type of the current instance.

(Inherited from Object)
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.

MemberwiseClone()

Creates a shallow copy of the current Object.

(Inherited from Object)
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.

ToString()

Returns a string that represents the current object.

(Inherited from Object)

Explicit Interface Implementations

IEnumerable.GetEnumerator()

Supports iteration over a generic collection.

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

Supports iteration over a strongly typed collection.

Extension Methods

CopyToDataTable<T>(IEnumerable<T>)

Returns a DataTable that contains copies of the DataRow objects, given an input IEnumerable<T> object where the generic parameter T is DataRow.

CopyToDataTable<T>(IEnumerable<T>, DataTable, LoadOption)

Copies DataRow objects to the specified DataTable, given an input IEnumerable<T> object where the generic parameter T is DataRow.

CopyToDataTable<T>(IEnumerable<T>, DataTable, LoadOption, FillErrorEventHandler)

Copies DataRow objects to the specified DataTable, given an input IEnumerable<T> object where the generic parameter T is DataRow.

Cast<TResult>(IEnumerable)

Casts the elements of an IEnumerable to the specified type.

OfType<TResult>(IEnumerable)

Filters the elements of an IEnumerable based on a specified type.

AsParallel(IEnumerable)

Enables parallelization of a query.

AsQueryable(IEnumerable)

Converts an IEnumerable to an IQueryable.

Ancestors<T>(IEnumerable<T>)

Returns a collection of elements that contains the ancestors of every node in the source collection.

Ancestors<T>(IEnumerable<T>, XName)

Returns a filtered collection of elements that contains the ancestors of every node in the source collection. Only elements that have a matching XName are included in the collection.

DescendantNodes<T>(IEnumerable<T>)

Returns a collection of the descendant nodes of every document and element in the source collection.

Descendants<T>(IEnumerable<T>)

Returns a collection of elements that contains the descendant elements of every element and document in the source collection.

Descendants<T>(IEnumerable<T>, XName)

Returns a filtered collection of elements that contains the descendant elements of every element and document in the source collection. Only elements that have a matching XName are included in the collection.

Elements<T>(IEnumerable<T>)

Returns a collection of the child elements of every element and document in the source collection.

Elements<T>(IEnumerable<T>, XName)

Returns a filtered collection of the child elements of every element and document in the source collection. Only elements that have a matching XName are included in the collection.

InDocumentOrder<T>(IEnumerable<T>)

Returns a collection of nodes that contains all nodes in the source collection, sorted in document order.

Nodes<T>(IEnumerable<T>)

Returns a collection of the child nodes of every document and element in the source collection.

Remove<T>(IEnumerable<T>)

Removes every node in the source collection from its parent node.

Applies to

Thread Safety

This type is thread safe.