Aspect that, when applied to a field or property, includes that member in the cache key generation for the declaring type when instances are used as parameters of cached methods.
Implements
Namespace: Metalama.Patterns.Caching.Aspects
Assembly: Metalama.Patterns.Caching.Aspects.dll
Syntax
public sealed class CacheKeyAttribute : FieldOrPropertyAspect, IAspect<IFieldOrProperty>, IAspect, ICompileTimeSerializable, ITemplateProvider, IEligible<IFieldOrProperty>Remarks
When a cached method has a parameter of a custom type, Metalama Caching needs to generate a unique string to represent the value in the cache key. The CacheKeyAttribute aspect automatically implements the IFormattable<T> interface for the CacheKeyFormatting role, including all marked fields and properties in the generated cache key.
As a best practice, include the full type name in cache keys to avoid collisions between different types that share the same identifying properties.
Examples
public class Product
{
[CacheKey]
public int Id { get; }
[CacheKey]
public string Category { get; }
public string Description { get; } // Not part of cache key
}
Constructors
| Name | Description |
|---|---|
| CacheKeyAttribute() |
Methods
| Name | Description |
|---|---|
| BuildAspect(IAspectBuilder<IFieldOrProperty>) | Defines the aspect implementation by adding advice, child aspects, and validators to the target declaration. |