Table of Contents

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

pattern string

The 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

key string

The unique identifier of the object to delete.

Returns

Task

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

key string

The unique identifier of the object to retrieve.

updateExpiration bool

Indicates 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 T associated 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

key string

The unique identifier of the object to retrieve.

ttlOverride TimeSpan?

An optional time-to-live value that overrides the default expiration period; if null, the default TTL is used.

updateExpiration bool

A 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

key string

The cache key used to identify the stored object.

factory Func<Task<T>>

The asynchronous function executed to produce the object when no cached value exists for the given key.

ttl TimeSpan?

The optional expiration period for the cached entry; if null, the default cache lifetime is applied.

cancellationToken CancellationToken

The 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

groupedField GroupedField

The grouped field used to categorize and identify the cached object.

patientId ObjectId

The identifier of the patient the object is associated with.

factory Func<Task<T>>

The asynchronous factory delegate invoked to produce the object when it is not found in the cache.

ttl TimeSpan?

The optional time-to-live duration applied to the cached entry.

cancellationToken CancellationToken

The 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

key string

The cache key used to identify the stored value.

loader Func<Task<string>>

The asynchronous function invoked to produce the value when no cached entry exists for the specified key.

ttlOverride TimeSpan?

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 null when no value is available.

GetValue(string)

Retrieves the string value associated with the specified key.

string? GetValue(string key)

Parameters

key string

The key used to look up the value.

Returns

string

The value associated with the key, or null if 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

key string

The identifier under which the object will be stored.

obj T

The object to be stored.

updateExpiration bool

Specifies whether the expiration time of the entry should be refreshed. Defaults to true.

Returns

Task

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

key string

The identifier under which the object will be stored.

obj T

The object to store.

ttlOverride TimeSpan?

An optional TimeSpan that overrides the default time-to-live for the stored object.

updateExpiration bool

A value indicating whether the expiration of the stored object should be updated based on the provided TTL.

Returns

Task

A Task that represents the asynchronous storage operation.

Type Parameters

T

SetValue(string, string)

Stores the specified value associated with the given key.

void SetValue(string key, string value)

Parameters

key string

The identifier used to associate the value.

value string

The value to store for the specified key.