using TakeoutSaaS.Domain.Dictionary.Enums;

namespace TakeoutSaaS.Application.Dictionary.Abstractions;

/// <summary>
/// 字典两级缓存访问接口。
/// </summary>
public interface IDictionaryHybridCache
{
    /// <summary>
    /// 读取缓存，不存在时通过工厂生成并回填。
    /// </summary>
    Task<T?> GetOrCreateAsync<T>(
        string key,
        TimeSpan ttl,
        Func<CancellationToken, Task<T?>> factory,
        CancellationToken cancellationToken = default);

    /// <summary>
    /// 按前缀失效缓存。
    /// </summary>
    Task InvalidateAsync(
        string prefix,
        CacheInvalidationOperation operation = CacheInvalidationOperation.Update,
        CancellationToken cancellationToken = default);
}
