CacheExtensions.Set Method

Definition

Overloads

Set<TItem>(IMemoryCache, Object, TItem)

Associate a value with a key in the IMemoryCache.

Set<TItem>(IMemoryCache, Object, TItem, MemoryCacheEntryOptions)

Sets a cache entry with the given key and value and apply the values of an existing MemoryCacheEntryOptions to the created entry.

Set<TItem>(IMemoryCache, Object, TItem, IChangeToken)

Sets a cache entry with the given key and value that will expire when IChangeToken expires.

Set<TItem>(IMemoryCache, Object, TItem, DateTimeOffset)

Sets a cache entry with the given key and value that will expire in the given duration.

Set<TItem>(IMemoryCache, Object, TItem, TimeSpan)

Sets a cache entry with the given key and value that will expire in the given duration from now.

Set<TItem>(IMemoryCache, Object, TItem)

Source:
MemoryCacheExtensions.cs
Source:
MemoryCacheExtensions.cs
Source:
MemoryCacheExtensions.cs

Associate a value with a key in the IMemoryCache.

C#
public static TItem Set<TItem>(this Microsoft.Extensions.Caching.Memory.IMemoryCache cache, object key, TItem value);

Type Parameters

TItem

The type of the object to set.

Parameters

cache
IMemoryCache

The IMemoryCache instance this method extends.

key
Object

The key of the entry to set.

value
TItem

The value to associate with the key.

Returns

TItem

The value that was set.

Applies to

.NET 10 (package-provided) y otras versiones
Producto Versiones
.NET 8 (package-provided), 9 (package-provided), 10 (package-provided)
.NET Standard 2.0 (package-provided)

Set<TItem>(IMemoryCache, Object, TItem, MemoryCacheEntryOptions)

Source:
MemoryCacheExtensions.cs
Source:
MemoryCacheExtensions.cs
Source:
MemoryCacheExtensions.cs

Sets a cache entry with the given key and value and apply the values of an existing MemoryCacheEntryOptions to the created entry.

C#
public static TItem Set<TItem>(this Microsoft.Extensions.Caching.Memory.IMemoryCache cache, object key, TItem value, Microsoft.Extensions.Caching.Memory.MemoryCacheEntryOptions? options);

Type Parameters

TItem

The type of the object to set.

Parameters

cache
IMemoryCache

The IMemoryCache instance this method extends.

key
Object

The key of the entry to set.

value
TItem

The value to associate with the key.

options
MemoryCacheEntryOptions

The existing MemoryCacheEntryOptions instance to apply to the new entry.

Returns

TItem

The value that was set.

Applies to

.NET 10 (package-provided) y otras versiones
Producto Versiones
.NET 8 (package-provided), 9 (package-provided), 10 (package-provided)
.NET Standard 2.0 (package-provided)

Set<TItem>(IMemoryCache, Object, TItem, IChangeToken)

Source:
MemoryCacheExtensions.cs
Source:
MemoryCacheExtensions.cs
Source:
MemoryCacheExtensions.cs

Sets a cache entry with the given key and value that will expire when IChangeToken expires.

C#
public static TItem Set<TItem>(this Microsoft.Extensions.Caching.Memory.IMemoryCache cache, object key, TItem value, Microsoft.Extensions.Primitives.IChangeToken expirationToken);

Type Parameters

TItem

The type of the object to set.

Parameters

cache
IMemoryCache

The IMemoryCache instance this method extends.

key
Object

The key of the entry to set.

value
TItem

The value to associate with the key.

expirationToken
IChangeToken

The IChangeToken that causes the cache entry to expire.

Returns

TItem

The value that was set.

Applies to

.NET 10 (package-provided) y otras versiones
Producto Versiones
.NET 8 (package-provided), 9 (package-provided), 10 (package-provided)
.NET Standard 2.0 (package-provided)

Set<TItem>(IMemoryCache, Object, TItem, DateTimeOffset)

Source:
MemoryCacheExtensions.cs
Source:
MemoryCacheExtensions.cs
Source:
MemoryCacheExtensions.cs

Sets a cache entry with the given key and value that will expire in the given duration.

C#
public static TItem Set<TItem>(this Microsoft.Extensions.Caching.Memory.IMemoryCache cache, object key, TItem value, DateTimeOffset absoluteExpiration);

Type Parameters

TItem

The type of the object to set.

Parameters

cache
IMemoryCache

The IMemoryCache instance this method extends.

key
Object

The key of the entry to set.

value
TItem

The value to associate with the key.

absoluteExpiration
DateTimeOffset

The point in time at which the cache entry will expire.

Returns

TItem

The value that was set.

Applies to

.NET 10 (package-provided) y otras versiones
Producto Versiones
.NET 8 (package-provided), 9 (package-provided), 10 (package-provided)
.NET Standard 2.0 (package-provided)

Set<TItem>(IMemoryCache, Object, TItem, TimeSpan)

Source:
MemoryCacheExtensions.cs
Source:
MemoryCacheExtensions.cs
Source:
MemoryCacheExtensions.cs

Sets a cache entry with the given key and value that will expire in the given duration from now.

C#
public static TItem Set<TItem>(this Microsoft.Extensions.Caching.Memory.IMemoryCache cache, object key, TItem value, TimeSpan absoluteExpirationRelativeToNow);

Type Parameters

TItem

The type of the object to set.

Parameters

cache
IMemoryCache

The IMemoryCache instance this method extends.

key
Object

The key of the entry to set.

value
TItem

The value to associate with the key.

absoluteExpirationRelativeToNow
TimeSpan

The duration from now after which the cache entry will expire.

Returns

TItem

The value that was set.

Applies to

.NET 10 (package-provided) y otras versiones
Producto Versiones
.NET 8 (package-provided), 9 (package-provided), 10 (package-provided)
.NET Standard 2.0 (package-provided)