-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathHybridCacheAttribute.cs
More file actions
39 lines (36 loc) · 1.43 KB
/
HybridCacheAttribute.cs
File metadata and controls
39 lines (36 loc) · 1.43 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
using System;
namespace ZibStack.NET.Aop;
/// <summary>
/// Built-in aspect that caches method return values using <c>Microsoft.Extensions.Caching.Hybrid.HybridCache</c>.
/// Unlike <see cref="CacheAttribute"/> (which uses a simple in-memory dictionary), this aspect
/// integrates with the .NET HybridCache infrastructure and supports L1/L2 caching (memory + Redis, etc.).
///
/// <para>
/// Requires <c>Microsoft.Extensions.Caching.Hybrid</c> NuGet package and HybridCache registered in DI:
/// <code>builder.Services.AddHybridCache();</code>
/// </para>
///
/// <para>
/// The built-in <see cref="HybridCacheHandler"/> is registered automatically by
/// <c>AddAop()</c> when <c>HybridCache</c> is available in DI.
/// </para>
/// </summary>
/// <example>
/// <code>
/// [HybridCache(DurationSeconds = 120)]
/// public async Task<Product> GetProductAsync(int id) { ... }
/// </code>
/// </example>
[AspectHandler(typeof(HybridCacheHandler<>))]
[AttributeUsage(AttributeTargets.Method | AttributeTargets.Class, AllowMultiple = false, Inherited = true)]
public sealed class HybridCacheAttribute : AspectAttribute
{
/// <summary>
/// Cache entry time-to-live in seconds. Default: 300 (5 minutes).
/// </summary>
public int DurationSeconds { get; set; } = 300;
/// <summary>
/// Custom cache key template. See <see cref="CacheAttribute.KeyTemplate"/> for syntax.
/// </summary>
public string? KeyTemplate { get; set; }
}