50 lines
1.4 KiB
C#
50 lines
1.4 KiB
C#
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;
|
||
}
|
||
}
|
||
}
|
||
|