ObjectCache 类

定义

表示一个对象缓存并提供用于访问该对象缓存的基方法和属性。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))
继承
ObjectCache
派生
实现

注解

ObjectCache类型是内存中对象缓存的主要类型。The ObjectCache type is the primary type for the in-memory object cache. 若要开发自定义缓存实现, 请从ObjectCache类派生。To develop a custom cache implementation, you derive from the ObjectCache class.

备注

类是新.NET Framework 4.NET Framework 4的, 而不是。 ObjectCacheThe ObjectCache class is new as of the .NET Framework 4.NET Framework 4.

内置MemoryCache类派生ObjectCache自类。The built-in MemoryCache class derives from the ObjectCache class. 类是派生自.NET Framework 4.NET Framework 4 ObjectCache类的中唯一具体的对象缓存实现。 MemoryCacheThe MemoryCache class is the only concrete object cache implementation in the .NET Framework 4.NET Framework 4 that derives from the ObjectCache class.

继承者说明

由于类型仅表示公共缓存函数, 因此不需要ObjectCache实例化和获取实例的方式。 ObjectCacheBecause the ObjectCache type represents only common cache functions, there is no requirement for how an ObjectCache instance must be instantiated and obtained. 此外, 不要求ObjectCache类的具体实现必须为单一实例。In addition, there is no requirement that concrete implementations of the ObjectCache class must be singletons.

MemoryCache不是单一实例, 但您应该只创建一个或多MemoryCache个实例, 而缓存项的代码应使用这些实例。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.

ObjectCache类继承时, 必须重写其方法。When you inherit from the ObjectCache class, you must override its methods.

构造函数

ObjectCache()

从派生类中的构造函数进行调用以便初始化 ObjectCache 类。Called from constructors in derived classes in order to initialize the ObjectCache class.

字段

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.

属性

DefaultCacheCapabilities

在派生类中重写时,获取缓存实现所提供的功能的说明。When overridden in a derived class, gets a description of the features that a cache implementation provides.

Host

获取或设置对托管宿主环境的引用,该环境可用于 ObjectCache 实现并且可为 ObjectCache 实现提供宿主特定服务。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]

获取或设置 ObjectCache 类的默认索引器。Gets or sets the default indexer for the ObjectCache class.

Name

获取某个特定 ObjectCache 实例的名称。Gets the name of a specific ObjectCache instance.

方法

Add(CacheItem, CacheItemPolicy)

在派生类中重写时,尝试以 CacheItem 实例的形式将缓存项插入缓存中,并添加有关应如何逐出该项的详细信息。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)

在派生类中重写时,向缓存中插入指定的 CacheItem 对象,同时指定有关如何逐出该项的信息。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)

在派生类中重写时,创建一个 CacheEntryChangeMonitor 对象,该对象可触发事件以响应对指定缓存项的更改。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.

(继承自 Object)
Get(String, String)

在派生类中重写时,以对象的形式获取缓存中的指定缓存项。When overridden in a derived class, gets the specified cache entry from the cache as an object.

GetCacheItem(String, String)

在派生类中重写时,以 CacheItem 实例的形式获取缓存中的指定缓存项。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.

(继承自 Object)
GetType()

获取当前实例的 TypeGets the Type of the current instance.

(继承自 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()

创建当前 Object 的浅表副本。Creates a shallow copy of the current Object.

(继承自 Object)
Remove(String, String)

在派生类中重写时,从缓存中移除缓存项。When overridden in a derived class, removes the cache entry from the cache.

Set(CacheItem, CacheItemPolicy)

在派生类中重写时,以 CacheItem 实例的形式向缓存中插入缓存项,同时指定有关如何逐出该项的信息。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.

(继承自 Object)

显式界面实现

IEnumerable.GetEnumerator()

支持对泛型集合进行迭代。Supports iteration over a generic collection.

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

支持对强类型集合迭代。Supports iteration over a strongly typed collection.

扩展方法

CopyToDataTable<T>(IEnumerable<T>)

在给定其泛型参数 TDataTable 的输入 DataRow 对象的情况下,返回包含 IEnumerable<T> 对象副本的 DataRowReturns 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)

在给定其泛型参数 TDataRow 的输入 DataTable 对象的情况下,将 IEnumerable<T> 对象复制到指定的 DataRowCopies 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)

在给定其泛型参数 TDataRow 的输入 DataTable 对象的情况下,将 IEnumerable<T> 对象复制到指定的 DataRowCopies DataRow objects to the specified DataTable, given an input IEnumerable<T> object where the generic parameter T is DataRow.

Cast<TResult>(IEnumerable)

IEnumerable 的元素强制转换为指定的类型。Casts the elements of an IEnumerable to the specified type.

OfType<TResult>(IEnumerable)

根据指定类型筛选 IEnumerable 的元素。Filters the elements of an IEnumerable based on a specified type.

AsParallel(IEnumerable)

启用查询的并行化。Enables parallelization of a query.

AsQueryable(IEnumerable)

IEnumerable 转换为 IQueryableConverts 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. 集合中仅包括具有匹配 XName 的元素。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. 集合中仅包括具有匹配 XName 的元素。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. 集合中仅包括具有匹配 XName 的元素。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.

适用于

线程安全性

此类型是线程安全的。This type is thread safe.