ObjectCache.AddOrGetExisting 方法

定义

在派生类中重写时,尝试将缓存条目插入缓存,并返回具有匹配键的现有缓存项。

重载

名称 说明
AddOrGetExisting(CacheItem, CacheItemPolicy)

在派生类中重写时,将指定的 CacheItem 对象插入缓存中,并指定有关如何逐出条目的信息。

AddOrGetExisting(String, Object, DateTimeOffset, String)

在派生类中重写时,通过使用键、缓存条目的对象、绝对过期值以及要向其添加缓存的可选区域,将缓存项插入缓存中。

AddOrGetExisting(String, Object, CacheItemPolicy, String)

在派生类中重写时,在缓存中插入缓存项、指定缓存项的键和值,以及有关如何逐出条目的信息。

注解

该方法 AddOrGetExisting 重载在缓存中插入一个条目。 如果已存在具有匹配键的缓存项,则返回现有条目。 缓存项可以是对象 CacheItem 或泛型对象。

重载和AddOrGetExisting重载之间存在Add一个差异。 当这些重载的方法尝试插入缓存项时,如果发现现有条目具有与现有插入缓存项匹配的键,则 AddOrGetExisting 重载将返回现有缓存项。 Add重载不会。

AddOrGetExisting(CacheItem, CacheItemPolicy)

Source:
ObjectCache.cs
Source:
ObjectCache.cs
Source:
ObjectCache.cs
Source:
ObjectCache.cs

在派生类中重写时,将指定的 CacheItem 对象插入缓存中,并指定有关如何逐出条目的信息。

public:
 abstract System::Runtime::Caching::CacheItem ^ AddOrGetExisting(System::Runtime::Caching::CacheItem ^ value, System::Runtime::Caching::CacheItemPolicy ^ policy);
public abstract System.Runtime.Caching.CacheItem AddOrGetExisting(System.Runtime.Caching.CacheItem value, System.Runtime.Caching.CacheItemPolicy policy);
abstract member AddOrGetExisting : System.Runtime.Caching.CacheItem * System.Runtime.Caching.CacheItemPolicy -> System.Runtime.Caching.CacheItem
Public MustOverride Function AddOrGetExisting (value As CacheItem, policy As CacheItemPolicy) As CacheItem

参数

value
CacheItem

要插入的对象。

policy
CacheItemPolicy

一个对象,其中包含缓存项的逐出详细信息。 此对象提供的逐出选项比简单的绝对到期时间更多。

返回

如果存在具有相同键的缓存项,则指定缓存项;否则,为 null.

适用于

AddOrGetExisting(String, Object, DateTimeOffset, String)

Source:
ObjectCache.cs
Source:
ObjectCache.cs
Source:
ObjectCache.cs
Source:
ObjectCache.cs

在派生类中重写时,通过使用键、缓存条目的对象、绝对过期值以及要向其添加缓存的可选区域,将缓存项插入缓存中。

public abstract object AddOrGetExisting(string key, object value, DateTimeOffset absoluteExpiration, string regionName = default);
abstract member AddOrGetExisting : string * obj * DateTimeOffset * string -> obj
Public MustOverride Function AddOrGetExisting (key As String, value As Object, absoluteExpiration As DateTimeOffset, Optional regionName As String = Nothing) As Object

参数

key
String

缓存项的唯一标识符。

value
Object

要插入的对象。

absoluteExpiration
DateTimeOffset

缓存项过期的固定日期和时间。

regionName
String

Optional. 如果实现了区域,可以在缓存中添加缓存条目的命名区域。 可选参数的默认值为 null

返回

如果存在具有相同键的缓存项,则指定的缓存项的值;否则,为 null.

注解

此方法 AddOrGetExisting(String, Object, DateTimeOffset, String) 重载返回对象值,而不是对象 CacheItem

适用于

AddOrGetExisting(String, Object, CacheItemPolicy, String)

Source:
ObjectCache.cs
Source:
ObjectCache.cs
Source:
ObjectCache.cs
Source:
ObjectCache.cs

在派生类中重写时,在缓存中插入缓存项、指定缓存项的键和值,以及有关如何逐出条目的信息。

public abstract object AddOrGetExisting(string key, object value, System.Runtime.Caching.CacheItemPolicy policy, string regionName = default);
abstract member AddOrGetExisting : string * obj * System.Runtime.Caching.CacheItemPolicy * string -> obj
Public MustOverride Function AddOrGetExisting (key As String, value As Object, policy As CacheItemPolicy, Optional regionName As String = Nothing) As Object

参数

key
String

缓存项的唯一标识符。

value
Object

要插入的对象。

policy
CacheItemPolicy

一个对象,其中包含缓存项的逐出详细信息。 此对象提供的逐出选项比简单的绝对到期时间更多。

regionName
String

Optional. 如果实现了区域,可以在缓存中添加缓存条目的命名区域。 可选参数的默认值为 null

返回

如果存在具有相同键的缓存项,则指定的缓存项的值;否则,为 null.

注解

该方法 AddOrGetExisting(String, Object, CacheItemPolicy, String) 返回对象值,而不是对象 CacheItem

适用于