-
-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathCachedAttribute.cs
More file actions
31 lines (27 loc) · 1.01 KB
/
CachedAttribute.cs
File metadata and controls
31 lines (27 loc) · 1.01 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
using ConsoleSample.Middleware;
using Foundatio.Mediator;
namespace ConsoleSample;
/// <summary>
/// Specifies that the handler method should cache its response.
/// Subsequent calls with the same message will return the cached value without executing the handler.
/// The message type must implement value equality (records work automatically).
/// </summary>
/// <example>
/// <code>
/// [Cached(DurationSeconds = 60)]
/// public Result<Order> Handle(GetOrder query) { ... }
/// </code>
/// </example>
[UseMiddleware(typeof(CachingMiddleware))]
[AttributeUsage(AttributeTargets.Method, AllowMultiple = false, Inherited = true)]
public sealed class CachedAttribute : Attribute
{
/// <summary>
/// Cache duration in seconds. Default is 300 (5 minutes).
/// </summary>
public int DurationSeconds { get; set; } = 300;
/// <summary>
/// Whether to use a sliding expiration (resets on each access). Default is false (absolute expiration).
/// </summary>
public bool SlidingExpiration { get; set; }
}