Class MemoryCacheExtension
- Namespace
- Arc4u.Configuration.Memory
- Assembly
- Arc4u.Caching.dll
Extension methods to register the options of a memory cache.
public static class MemoryCacheExtension
- Inheritance
-
MemoryCacheExtension
- Inherited Members
Methods
AddMemoryCache(IServiceCollection, string, IConfiguration, string)
Registers the options of the memory cache with the given name from a configuration section. Nothing is registered when the section does not exist.
public static IServiceCollection AddMemoryCache(this IServiceCollection services, string name, IConfiguration configuration, string sectionName)
Parameters
servicesIServiceCollectionThe service collection.
namestringThe name of the cache, as used in Name.
configurationIConfigurationThe application configuration.
sectionNamestringThe path of the section that holds the MemoryCacheOption values.
Returns
- IServiceCollection
The same IServiceCollection, for chaining.
Exceptions
- ArgumentException
nameis null or empty and the section exists.
AddMemoryCache(IServiceCollection, string, Action<MemoryCacheOption>)
Registers the options of the memory cache with the given name.
public static IServiceCollection AddMemoryCache(this IServiceCollection services, string name, Action<MemoryCacheOption> options)
Parameters
servicesIServiceCollectionThe service collection.
namestringThe name of the cache, as used in Name.
optionsAction<MemoryCacheOption>The action that configures the options.
Returns
- IServiceCollection
The same IServiceCollection, for chaining.
Examples
builder.Services.AddMemoryCache("Volatile", o => o.SizeLimitInMB = 50);
Exceptions
- ArgumentException
nameis null or empty.