Class LocalCache
Represents a local caching service that implements the ICacheService interface using an in-memory cache provided by IMemoryCache.
Inherited Members
Namespace: Innovt.Core.Caching
Assembly: Innovt.Core.dll
Syntax
public sealed class LocalCache : ICacheService, IDisposable
Remarks
This class provides a concrete implementation of the ICacheService interface using an in-memory cache for storing and retrieving data. It is designed for local caching within an application.
Constructors
| Edit this page View SourceLocalCache(IMemoryCache)
Initializes a new instance of the LocalCache class with the specified IMemoryCache.
Declaration
public LocalCache(IMemoryCache memoryCache)
Parameters
| Type | Name | Description |
|---|---|---|
| IMemoryCache | memoryCache | The in-memory cache implementation provided by IMemoryCache. |
Exceptions
| Type | Condition |
|---|---|
| ArgumentNullException | Thrown when |
Methods
| Edit this page View SourceDispose()
Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources.
Declaration
public void Dispose()
~LocalCache()
Finalizes an instance of the LocalCache class.
Declaration
protected ~LocalCache()
GetValue<T>(string)
Gets the cached value associated with the specified key.
Declaration
public T GetValue<T>(string key)
Parameters
| Type | Name | Description |
|---|---|---|
| string | key | The unique identifier for the cached item. |
Returns
| Type | Description |
|---|---|
| T | The cached value if found; otherwise, the default value for the type. |
Type Parameters
| Name | Description |
|---|---|
| T | The type of the cached value. |
Remove(string)
Removes a cached value associated with the specified key.
Declaration
public void Remove(string key)
Parameters
| Type | Name | Description |
|---|---|---|
| string | key | The unique identifier for the cached item to be removed. |
SetValue<T>(string, T, TimeSpan)
Sets a value in the cache with the specified key and expiration duration.
Declaration
public void SetValue<T>(string key, T entity, TimeSpan expiration)
Parameters
| Type | Name | Description |
|---|---|---|
| string | key | The unique identifier for the cached item. |
| T | entity | The value to be cached. |
| TimeSpan | expiration | The time duration for which the value should be cached. |
Type Parameters
| Name | Description |
|---|---|
| T | The type of the value to be cached. |