Class MemoryCache
An ICache stored in the memory of the process, resolved with the kind Memory. Values are serialized like in the other distributed caches.
The size limit and the compaction percentage come from the MemoryCacheOption named after the store.
[Export("Memory", typeof(ICache))]
public class MemoryCache : BaseDistributeCache<MemoryCache>, ICache, IDisposable
- Inheritance
-
MemoryCache
- Implements
- Inherited Members
Constructors
MemoryCache(ILogger<MemoryCache>, IServiceProvider, IOptionsMonitor<MemoryCacheOption>)
Initializes a new instance of the MemoryCache class.
public MemoryCache(ILogger<MemoryCache> logger, IServiceProvider container, IOptionsMonitor<MemoryCacheOption> options)
Parameters
loggerILogger<MemoryCache>The logger.
containerIServiceProviderThe service provider used to resolve the serializer.
optionsIOptionsMonitor<MemoryCacheOption>The named options of the memory caches.
Methods
Initialize(string)
Creates the underlying memory cache from the options named store and resolves the IObjectSerialization
(the one registered with SerializerName if any, otherwise the default one).
When no serializer can be resolved the cache stays uninitialized and the operations throw CacheNotInitializedException.
Calling it again on an initialized cache only logs a warning.
public override void Initialize(string store)
Parameters
storestringThe name of the cache, as declared in the configuration.
Exceptions
- ArgumentException
storeis empty.
ToString()
Returns the name of the cache given to Initialize(string).
public override string ToString()
Returns
- string
The name of the cache.
Exceptions
- InvalidOperationException
The cache has not been initialized.