Interface ICacheService
Represents a caching service interface for storing and retrieving data.
Inherited Members
Namespace: Innovt.Core.Caching
Assembly: Innovt.Core.dll
Syntax
public interface ICacheService : IDisposable
Remarks
This interface defines methods for retrieving and caching data, as well as removing cached data. Implement this interface to create a caching service for your application.
Methods
| Edit this page View SourceGetValueOrCreate<T>(string, Func<CancellationToken, Task<T>>, TimeSpan, CancellationToken)
Asynchronously retrieves a cached value associated with the specified key, or creates and caches it if not found.
Declaration
Task<T> GetValueOrCreate<T>(string key, Func<CancellationToken, Task<T>> factory, TimeSpan expiration, CancellationToken cancellationToken)
Parameters
Type | Name | Description |
---|---|---|
string | key | The unique identifier for the cached item. |
Func<CancellationToken, Task<T>> | factory | A factory function to create the value if not found. |
TimeSpan | expiration | The time duration for which the value should be cached. |
CancellationToken | cancellationToken | A token to monitor for cancellation requests. |
Returns
Type | Description |
---|---|
Task<T> | The cached value if found, or a newly created value from the factory function if not found. |
Type Parameters
Name | Description |
---|---|
T | The type of the cached value. |
GetValue<T>(string)
Gets the cached value associated with the specified key.
Declaration
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. |
GetValue<T>(string, Func<CancellationToken, Task<T>>, CancellationToken)
Declaration
Task<T> GetValue<T>(string key, Func<CancellationToken, Task<T>> factory, CancellationToken cancellationToken)
Parameters
Type | Name | Description |
---|---|---|
string | key | |
Func<CancellationToken, Task<T>> | factory | |
CancellationToken | cancellationToken |
Returns
Type | Description |
---|---|
Task<T> |
Type Parameters
Name | Description |
---|---|
T |
Remove(string)
Removes a cached value associated with the specified key.
Declaration
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
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. |