Interface ICacheService
- Namespace
- adas_core.Application.Services.Interfaces
- Assembly
- adas-core.Application.dll
public interface ICacheService
- Extension Methods
Methods
CleanCache()
Clears the application cache, removing all cached entries.
void CleanCache()
DeleteByPatternAsync(string)
Asynchronously deletes entries matching the specified pattern and returns the number of deleted items.
Task<long> DeleteByPatternAsync(string pattern)
Parameters
patternstringThe pattern used to match the entries to be deleted.
Returns
- Task<long>
A task that represents the asynchronous delete operation. The task result contains the total number of entries that were deleted.
DeleteObjectAsync(string)
Asynchronously deletes an object identified by the specified key.
Task DeleteObjectAsync(string key)
Parameters
keystringThe unique identifier of the object to delete.
Returns
GetObjectAsync<T>(string, bool)
Asynchronously retrieves an object associated with the specified key, returning null if no entry is found.
When updateExpiration is true, the expiration of the retrieved entry is extended upon access.
Task<T?> GetObjectAsync<T>(string key, bool updateExpiration = true)
Parameters
keystringThe unique identifier of the object to retrieve.
updateExpirationboolIndicates whether the expiration of the entry should be extended when it is successfully retrieved. Defaults to true.
Returns
- Task<T>
A task that represents the asynchronous retrieval operation. The task result contains the object of type
Tassociated with the key, or null if no matching entry exists.
Type Parameters
T
GetObjectAsync<T>(string, TimeSpan?, bool)
Asynchronously retrieves an object of type T associated with the specified key.
Supports an optional ttlOverride to apply a custom time-to-live and an updateExpiration flag
to control whether the entry's expiration is refreshed on access.
Task<T?> GetObjectAsync<T>(string key, TimeSpan? ttlOverride, bool updateExpiration)
Parameters
keystringThe unique identifier of the object to retrieve.
ttlOverrideTimeSpan?An optional time-to-live value that overrides the default expiration period; if null, the default TTL is used.
updateExpirationboolA value indicating whether the object's expiration should be extended when it is successfully retrieved.
Returns
- Task<T>
A Task<TResult> that represents the asynchronous operation, containing the retrieved object of type
T, or null if the object is not found.
Type Parameters
T
GetOrSetObjectAsync<T>(string, Func<Task<T>>, TimeSpan?, CancellationToken)
Asynchronously retrieves an object associated with the specified key from the cache, or invokes the factory to create and cache a new one when the key is not found.
Task<T> GetOrSetObjectAsync<T>(string key, Func<Task<T>> factory, TimeSpan? ttl = null, CancellationToken cancellationToken = default)
Parameters
keystringThe cache key used to identify the stored object.
factoryFunc<Task<T>>The asynchronous function executed to produce the object when no cached value exists for the given key.
ttlTimeSpan?The optional expiration period for the cached entry; if null, the default cache lifetime is applied.
cancellationTokenCancellationTokenThe token used to cancel the asynchronous operation.
Returns
- Task<T>
A task that resolves to the cached or newly created object of type
T.
Type Parameters
T
GetOrSetObjectAsync<T>(GroupedField, ObjectId, Func<Task<T>>, TimeSpan?, CancellationToken)
Asynchronously retrieves a cached object identified by the patient and grouped field, or creates and stores it via the supplied factory when no cached value exists.
Task<T> GetOrSetObjectAsync<T>(GroupedField groupedField, ObjectId patientId, Func<Task<T>> factory, TimeSpan? ttl = null, CancellationToken cancellationToken = default)
Parameters
groupedFieldGroupedFieldThe grouped field used to categorize and identify the cached object.
patientIdObjectIdThe identifier of the patient the object is associated with.
factoryFunc<Task<T>>The asynchronous factory delegate invoked to produce the object when it is not found in the cache.
ttlTimeSpan?The optional time-to-live duration applied to the cached entry.
cancellationTokenCancellationTokenThe token to monitor for cancellation requests.
Returns
- Task<T>
A task containing the cached or newly created object of type
T.
Type Parameters
T
GetOrSetValueAsync(string, Func<Task<string>>, TimeSpan?)
Asynchronously retrieves a cached value for the specified key, or loads and stores it using the provided loader function when the key is not present.
Task<string?> GetOrSetValueAsync(string key, Func<Task<string>> loader, TimeSpan? ttlOverride = null)
Parameters
keystringThe cache key used to identify the stored value.
loaderFunc<Task<string>>The asynchronous function invoked to produce the value when no cached entry exists for the specified key.
ttlOverrideTimeSpan?An optional time-to-live duration that overrides the default expiration for the cached entry; when
null, the default TTL is used.
Returns
- Task<string>
A task that represents the asynchronous operation. The result is the cached or freshly loaded string value, or
nullwhen no value is available.
GetValue(string)
Retrieves the string value associated with the specified key.
string? GetValue(string key)
Parameters
keystringThe key used to look up the value.
Returns
- string
The value associated with the key, or
nullif the key is not found.
SetObjectAsync<T>(string, T, bool)
Asynchronously stores an object of type T using the specified key, optionally updating its expiration time.
When updateExpiration is true, the entry's expiration is refreshed; otherwise the existing expiration is preserved.
Task SetObjectAsync<T>(string key, T obj, bool updateExpiration = true)
Parameters
keystringThe identifier under which the object will be stored.
objTThe object to be stored.
updateExpirationboolSpecifies whether the expiration time of the entry should be refreshed. Defaults to true.
Returns
Type Parameters
T
SetObjectAsync<T>(string, T, TimeSpan?, bool)
Asynchronously stores the specified object associated with the given key, using an optional time-to-live override and expiration update behavior.
Task SetObjectAsync<T>(string key, T obj, TimeSpan? ttlOverride, bool updateExpiration)
Parameters
keystringThe identifier under which the object will be stored.
objTThe object to store.
ttlOverrideTimeSpan?An optional TimeSpan that overrides the default time-to-live for the stored object.
updateExpirationboolA value indicating whether the expiration of the stored object should be updated based on the provided TTL.
Returns
Type Parameters
T
SetValue(string, string)
Stores the specified value associated with the given key.
void SetValue(string key, string value)