chore: 提交现有修改

This commit is contained in:
2025-12-02 12:11:25 +08:00
parent 541b75ecd8
commit 5332c87d9d
37 changed files with 429 additions and 677 deletions

View File

@@ -10,22 +10,15 @@ namespace TakeoutSaaS.Infrastructure.Dictionary.Services;
/// <summary>
/// 基于 IDistributedCache 的字典缓存实现。
/// </summary>
public sealed class DistributedDictionaryCache : IDictionaryCache
public sealed class DistributedDictionaryCache(IDistributedCache cache, IOptions<DictionaryCacheOptions> options) : IDictionaryCache
{
private readonly IDistributedCache _cache;
private readonly DictionaryCacheOptions _options;
private readonly DictionaryCacheOptions _options = options.Value;
private readonly JsonSerializerOptions _serializerOptions = new(JsonSerializerDefaults.Web);
public DistributedDictionaryCache(IDistributedCache cache, IOptions<DictionaryCacheOptions> options)
{
_cache = cache;
_options = options.Value;
}
public async Task<IReadOnlyList<DictionaryItemDto>?> GetAsync(long tenantId, string code, CancellationToken cancellationToken = default)
{
var cacheKey = BuildKey(tenantId, code);
var payload = await _cache.GetAsync(cacheKey, cancellationToken);
var payload = await cache.GetAsync(cacheKey, cancellationToken);
if (payload == null || payload.Length == 0)
{
return null;
@@ -42,13 +35,13 @@ public sealed class DistributedDictionaryCache : IDictionaryCache
{
SlidingExpiration = _options.SlidingExpiration
};
return _cache.SetAsync(cacheKey, payload, options, cancellationToken);
return cache.SetAsync(cacheKey, payload, options, cancellationToken);
}
public Task RemoveAsync(long tenantId, string code, CancellationToken cancellationToken = default)
{
var cacheKey = BuildKey(tenantId, code);
return _cache.RemoveAsync(cacheKey, cancellationToken);
return cache.RemoveAsync(cacheKey, cancellationToken);
}
private static string BuildKey(long tenantId, string code)