=== Summary: 675 files | 7 generated | 484 fresh | 4605 untracked | 4268 adopted | 355 marked | 466 validated-ok | 2+0 stale (sig+body) | 0 skipped | 0 failed | elapsed 11:08:11.442 (40091.44s) ===
This commit is contained in:
@@ -12,6 +12,7 @@ namespace adas_core.Application.Services.Caching
|
||||
/// según CacheSettings y la entidad del key.
|
||||
/// Implementa ICacheService y delega en el backend elegido.
|
||||
/// </summary>
|
||||
/// <!-- aidoc:v1 sig=9f15289 -->
|
||||
public class CacheDispatcher(
|
||||
RedisService redis,
|
||||
CacheService memory,
|
||||
@@ -27,6 +28,7 @@ namespace adas_core.Application.Services.Caching
|
||||
/// </summary>
|
||||
/// <param name="key">The cache key used to determine the entity type and the corresponding cache backend.</param>
|
||||
/// <returns>The <see cref="ICacheService"/> instance that should handle caching for the supplied key.</returns>
|
||||
/// <!-- aidoc:v1 sig=26395d4 body=a1c4c59 -->
|
||||
private ICacheService SelectBackend(string key)
|
||||
{
|
||||
var entity = CacheKeyClassifier.Classify(key);
|
||||
@@ -56,6 +58,7 @@ namespace adas_core.Application.Services.Caching
|
||||
/// <param name="gf">The grouped field whose name contributes to the key.</param>
|
||||
/// <param name="patientId">The identifier of the patient associated with the grouped observation.</param>
|
||||
/// <returns>A formatted key string in the form <c>GroupedObs:{patientId}:{gf.Name}</c>.</returns>
|
||||
/// <!-- aidoc:v1 sig=72c65a6 -->
|
||||
private static string BuildGroupedKey(GroupedField gf, ObjectId patientId)
|
||||
=> $"GroupedObs:{patientId}:{gf.Name}";
|
||||
|
||||
@@ -65,6 +68,7 @@ namespace adas_core.Application.Services.Caching
|
||||
/// <param name="groupedField">The grouped field used to derive the cache key.</param>
|
||||
/// <param name="patientId">The patient identifier used to derive the cache key.</param>
|
||||
/// <returns>The <see cref="ICacheService"/> backend associated with the built grouped key.</returns>
|
||||
/// <!-- aidoc:v1 sig=2461014 -->
|
||||
private ICacheService SelectBackend(GroupedField groupedField, ObjectId patientId)
|
||||
=> SelectBackend(BuildGroupedKey(groupedField, patientId));
|
||||
|
||||
@@ -78,6 +82,7 @@ namespace adas_core.Application.Services.Caching
|
||||
/// <param name="ttl">An optional time-to-live duration for the cached object. If null, the backend's default expiration is applied.</param>
|
||||
/// <param name="cancellationToken">A token to observe while waiting for the operation to complete.</param>
|
||||
/// <returns>A task that represents the asynchronous operation, containing the retrieved or newly created object of type <typeparamref name="T"/>.</returns>
|
||||
/// <!-- aidoc:v1 sig=5407b21 -->
|
||||
public Task<T> GetOrSetObjectAsync<T>(
|
||||
string key,
|
||||
Func<Task<T>> factory,
|
||||
@@ -94,6 +99,7 @@ namespace adas_core.Application.Services.Caching
|
||||
/// <param name="loader">An asynchronous function that produces the value to cache when no existing entry is found.</param>
|
||||
/// <param name="ttl">An optional time-to-live duration after which the cached entry expires. If null, the backend's default TTL is used.</param>
|
||||
/// <returns>A task that represents the asynchronous operation, containing the cached or loaded string value, or null if no value could be obtained.</returns>
|
||||
/// <!-- aidoc:v1 sig=0bd9db4 -->
|
||||
public Task<string?> GetOrSetValueAsync(
|
||||
string key,
|
||||
Func<Task<string>> loader,
|
||||
@@ -113,6 +119,7 @@ namespace adas_core.Application.Services.Caching
|
||||
/// <param name="ttl">An optional time-to-live applied to the cached object. When <c>null</c>, the backend's default expiration is used.</param>
|
||||
/// <param name="cancellationToken">The token to observe for canceling the asynchronous operation.</param>
|
||||
/// <returns>A task that represents the asynchronous get-or-set operation, containing the retrieved or newly created object.</returns>
|
||||
/// <!-- aidoc:v1 sig=c950b98 -->
|
||||
public Task<T> GetOrSetObjectAsync<T>(
|
||||
GroupedField groupedField,
|
||||
ObjectId patientId,
|
||||
@@ -129,6 +136,7 @@ namespace adas_core.Application.Services.Caching
|
||||
/// </summary>
|
||||
/// <param name="key">The key used to select the backend and identify the value to set.</param>
|
||||
/// <param name="value">The value to associate with the specified key.</param>
|
||||
/// <!-- aidoc:v1 sig=3796865 -->
|
||||
public void SetValue(string key, string value)
|
||||
=> SelectBackend(key).SetValue(key, value);
|
||||
|
||||
@@ -137,6 +145,7 @@ namespace adas_core.Application.Services.Caching
|
||||
/// </summary>
|
||||
/// <param name="key">The key used to select the backend and retrieve the associated value.</param>
|
||||
/// <returns>The value associated with the key, or <c>null</c> if the selected backend returns no value.</returns>
|
||||
/// <!-- aidoc:v1 sig=f39f53d -->
|
||||
public string? GetValue(string key)
|
||||
=> SelectBackend(key).GetValue(key);
|
||||
|
||||
@@ -146,6 +155,7 @@ namespace adas_core.Application.Services.Caching
|
||||
/// <param name="key">The identifier used to select the appropriate backend and to look up the object.</param>
|
||||
/// <param name="upd">Indicates whether the underlying backend should perform an update during retrieval. Defaults to <c>true</c>.</param>
|
||||
/// <returns>A task that represents the asynchronous retrieval operation, containing the object of type <typeparamref name="T"/> or <c>null</c> if not found.</returns>
|
||||
/// <!-- aidoc:v1 sig=15709a1 -->
|
||||
public Task<T?> GetObjectAsync<T>(string key, bool upd = true)
|
||||
=> SelectBackend(key).GetObjectAsync<T>(key, upd);
|
||||
|
||||
@@ -157,6 +167,7 @@ namespace adas_core.Application.Services.Caching
|
||||
/// <param name="obj">The object to store in the selected backend.</param>
|
||||
/// <param name="upd">Indicates whether an update operation should be performed. Defaults to <c>true</c>.</param>
|
||||
/// <returns>A task that represents the asynchronous store operation.</returns>
|
||||
/// <!-- aidoc:v1 sig=9d84645 -->
|
||||
public Task SetObjectAsync<T>(string key, T obj, bool upd = true)
|
||||
=> SelectBackend(key).SetObjectAsync(key, obj, upd);
|
||||
|
||||
@@ -167,6 +178,7 @@ namespace adas_core.Application.Services.Caching
|
||||
/// <param name="ttl">An optional time-to-live applied to the object; if null, the backend's default is used.</param>
|
||||
/// <param name="upd">A flag indicating whether the retrieval should update the object's state (e.g., refresh expiration).</param>
|
||||
/// <returns>A task containing the deserialized object, or null if the object is not found in the selected backend.</returns>
|
||||
/// <!-- aidoc:v1 sig=4675112 -->
|
||||
public Task<T?> GetObjectAsync<T>(string key, TimeSpan? ttl, bool upd)
|
||||
=> SelectBackend(key).GetObjectAsync<T>(key, ttl, upd);
|
||||
|
||||
@@ -178,6 +190,8 @@ namespace adas_core.Application.Services.Caching
|
||||
/// <param name="ttl">The optional time-to-live duration for the stored object.</param>
|
||||
/// <param name="upd">Indicates whether to update an existing entry or create a new one.</param>
|
||||
/// <returns>A task that represents the asynchronous set operation.</returns>
|
||||
/// <!-- aidoc-review:v1 severity=medium kind=missing_param
|
||||
/// "Generic type parameter T (the type of the object being stored) is not documented" -->
|
||||
public Task SetObjectAsync<T>(string key, T obj, TimeSpan? ttl, bool upd)
|
||||
=> SelectBackend(key).SetObjectAsync(key, obj, ttl, upd);
|
||||
|
||||
@@ -186,6 +200,7 @@ namespace adas_core.Application.Services.Caching
|
||||
/// </summary>
|
||||
/// <param name="key">The identifier of the object to delete, also used to resolve the responsible backend.</param>
|
||||
/// <returns>A task that represents the asynchronous delete operation.</returns>
|
||||
/// <!-- aidoc:v1 sig=0dde5af -->
|
||||
public Task DeleteObjectAsync(string key)
|
||||
=> SelectBackend(key).DeleteObjectAsync(key);
|
||||
|
||||
@@ -194,12 +209,14 @@ namespace adas_core.Application.Services.Caching
|
||||
/// </summary>
|
||||
/// <param name="pattern">The pattern used to match entries for deletion in both storage backends.</param>
|
||||
/// <returns>The combined total number of entries deleted from Redis and in-memory storage.</returns>
|
||||
/// <!-- aidoc:v1 sig=fa6dca4 -->
|
||||
public async Task<long> DeleteByPatternAsync(string pattern)
|
||||
=> await redis.DeleteByPatternAsync(pattern) + await memory.DeleteByPatternAsync(pattern);
|
||||
|
||||
/// <summary>
|
||||
/// Clears all cached data from both the in-memory cache and the Redis cache, ensuring that stale entries are removed across all configured cache providers.
|
||||
/// </summary>
|
||||
/// <!-- aidoc:v1 sig=d5e5e8c body=c0791ef -->
|
||||
public void CleanCache()
|
||||
{
|
||||
memory.CleanCache();
|
||||
|
||||
Reference in New Issue
Block a user