Class CacheResultAttribute
Attribute to mark dispatch actions for result caching with configurable options. Applied at the class level to enable caching for the entire message handler result.
[AttributeUsage(AttributeTargets.Class)]
public sealed class CacheResultAttribute : Attribute
- Inheritance
-
CacheResultAttribute
- Inherited Members
- Extension Methods
Remarks
The handler must be free of observable side effects. A cached action's handler is run as
the value factory of HybridCache, and a value factory is not invoked once per dispatch. It runs
only on a miss, it is shared between concurrent callers of the same key so several dispatches produce one
invocation, and it can also run on a background task that no dispatch is awaiting. The number of handler
invocations is therefore unrelated to the number of dispatches in both directions, and no configuration
changes that.
Read it as: the handler answers "what is the value for this key", nothing more. Anything that must happen once per request -- writes, sends, counters, audit entries -- belongs outside a cached handler, because it will be skipped on a hit and may be repeated on a background refresh.
Properties
ExpirationSeconds
Gets or sets the cache expiration time in seconds. When set to 0 (default), uses the DefaultExpiration value configured in options.
public int ExpirationSeconds { get; set; }
Property Value
- int
The cache expiration time in seconds, or 0 to use the configured default.
IgnoreNullResult
Gets or sets a value indicating whether to ignore null results when caching. When true, null results are not cached. Default is true.
public bool IgnoreNullResult { get; set; }
Property Value
OnlyIfSuccess
Gets or sets a value indicating whether to cache only successful results. When true, only successful message results are cached. Default is true.
public bool OnlyIfSuccess { get; set; }
Property Value
Tags
Gets or sets the cache tags for this result. Used for bulk cache invalidation scenarios.
public string[] Tags { get; set; }
Property Value
- string[]
The cache tags for this result.