using System;
namespace Dpz.Core.SourceGenerator.Attributes;
/// <summary>
/// 标记会触发其它 <see cref="CacheAttribute" /> 方法缓存失效的写操作方法。
/// </summary>
/// <remarks>
/// <para>
/// 该特性应当标记在实现类的写操作方法上。源生成器会在被装饰方法 <c>await</c>
/// 完成之后,调用 <c>IFusionCache.RemoveByTagAsync</c> 清理 <see cref="Methods" />
/// 中指定方法对应的 method tag。
/// </para>
/// <para>
/// <see cref="Methods" /> 中列出的方法必须是同一实现类上已经标记了
/// <see cref="CacheAttribute" /> 的方法,否则生成器会输出 <c>DPZ_CACHE004</c> 编译错误。
/// </para>
/// </remarks>
[AttributeUsage(AttributeTargets.Method, Inherited = false)]
public sealed class InvalidateCacheAttribute : Attribute
{
/// <summary>
/// 需要在原方法成功返回后清理 method tag 的方法名列表。
/// </summary>
/// <remarks>
/// 推荐配合 <c>nameof()</c> 使用,例如:
/// <code>
/// [InvalidateCache(Methods = [nameof(GetTopArticlesAsync), nameof(GetPagesAsync)])]
/// public Task DeleteAsync(string id, CancellationToken cancellationToken = default)
/// </code>
/// </remarks>
public string[] Methods { get; set; } = [];
}
评论加载中...