Open sandboxFocus

Class InvalidateCacheAttribute

Custom attribute that, when applied to a method, causes an invocation of this method to remove from the cache the result of invocations of other given methods with the same parameter values.

Namespace: PostSharp.Patterns.Caching
Assembly: PostSharp.Patterns.Caching.dll
Syntax
[MulticastAttributeUsage(MulticastTargets.Method, AllowMultiple = true)]
[Metric("UsedFeatures", "Patterns.Caching.InvalidateCache")]
[ProvideAspectRole("CacheInvalidation")]
[AspectRoleDependency(AspectDependencyAction.Order, AspectDependencyPosition.After, "Validation")]
[AspectRoleDependency(AspectDependencyAction.Order, AspectDependencyPosition.After, "Tracing")]
[LinesOfCodeAvoided(1)]
[Serializer(typeof(InvalidateCacheAttribute.Serializer))]
public sealed class InvalidateCacheAttribute : MethodInterceptionAspect, IMethodLevelAspectBuildSemantics, IAspectBuildSemantics, IValidableAnnotation, IAsyncMethodInterceptionAspect, IMethodInterceptionAspect, IMethodLevelAspect, IAspect
Remarks

The invalidation happens after the target method returns. Each parameter of a cached method is matched with the parameter of the same name of the target method, regardless of their order, and the type of the target method parameter must be assignable to the type of the cached method parameter. Parameters annotated with NotCacheKeyAttribute are not matched. When no overload has all its parameters matched, the build fails with an error.

By default, the cached methods are looked up in the declaring type of the target method; use the constructor that takes a Type to specify another type. When the this instance is part of the cache key of an instance method (see IgnoreThisParameter), the target method must be an instance method of the same type or of a derived type. When a method name matches several cached overloads, set AllowMultipleOverloads to true to invalidate all of them.

To invalidate cached methods imperatively, use CachingServices.Invalidation. To decouple the invalidating methods from the cached methods, use cache dependencies (see ICachingContext).

Constructors

Name Description
InvalidateCacheAttribute(PortableFormatterConstructorContext)
InvalidateCacheAttribute(params string[])

Initializes a new instance of the InvalidateCacheAttribute class that invalidates methods of the same type as the type to which the current InvalidateCacheAttribute aspect is being applied.

InvalidateCacheAttribute(Type, params string[])

Initializes a new instance of the InvalidateCacheAttribute class that invalidates methods of a different type than the type to which the current InvalidateCacheAttribute aspect is being applied.

Properties

Name Description
AllowMultipleOverloads

Gets or sets a value indicating whether the current InvalidateCacheAttribute can match several overloads of the methods. The default value is false, which means that an error will be emitted if the current InvalidateCacheAttribute matches several methods of the same name.

See Also