live-forum/server/webapi/LiveForum/LiveForum.Code/AttributeExtend/ResponseCacheExtendAttribute.cs
2026-03-24 11:27:37 +08:00

50 lines
1.4 KiB
C#
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

using System;
namespace LiveForum.Code.AttributeExtend
{
/// <summary>
/// 响应缓存特性用于标记需要缓存的Action方法
/// </summary>
[AttributeUsage(AttributeTargets.Method, AllowMultiple = false)]
public class ResponseCacheExtendAttribute : Attribute
{
/// <summary>
/// 缓存时间默认3600秒1小时
/// </summary>
public int Duration { get; set; } = 3600;
/// <summary>
/// 影响缓存Key的查询参数名称数组参数排序后参与Key生成
/// 例如:["AgreementType"] 或 ["Platform", "CurrentVersion"]
/// </summary>
public string[] VaryByQueryKeys { get; set; }
/// <summary>
/// 自定义缓存Key前缀默认使用路径api/{Controller}/{Action}
/// </summary>
public string CacheKeyPrefix { get; set; }
/// <summary>
/// 是否启用缓存默认true
/// </summary>
public bool Enabled { get; set; } = true;
/// <summary>
/// 构造函数
/// </summary>
public ResponseCacheExtendAttribute()
{
}
/// <summary>
/// 构造函数
/// </summary>
/// <param name="duration">缓存时间(秒)</param>
public ResponseCacheExtendAttribute(int duration)
{
Duration = duration;
}
}
}