Open sandboxFocus

Class CacheAttribute

Custom attribute that, when applied on a method, causes the return value of the method to be cached for the specific list of arguments passed to this method call.

Namespace: PostSharp.Patterns.Caching
Assembly: PostSharp.Patterns.Caching.dll
Syntax
[Metric("UsedFeatures", "Patterns.Caching.Cache")]
[ProvideAspectRole("Caching")]
[AspectRoleDependency(AspectDependencyAction.Order, AspectDependencyPosition.After, "Validation")]
[AspectRoleDependency(AspectDependencyAction.Order, AspectDependencyPosition.After, "Tracing")]
[LinesOfCodeAvoided(3)]
[MulticastAttributeUsage(PersistMetaData = true)]
[Serializer(typeof(CacheAttribute.Serializer))]
public sealed class CacheAttribute : MethodInterceptionAspect, IMethodLevelAspectBuildSemantics, IAspectBuildSemantics, IValidableAnnotation, IAsyncMethodInterceptionAspect, IMethodInterceptionAspect, IMethodLevelAspect, IAspect
Remarks

There are several ways to configure the behavior of the CacheAttribute aspect: you can set the properties of the CacheAttribute class, such as AbsoluteExpiration or SlidingExpiration. You can add the CacheConfigurationAttribute custom attribute to the declaring type, a base type, or the declaring assembly. Finally, you can define a profile by setting the ProfileName property and configure the profile at run time by accessing the Profiles collection of the CachingServices class.

Use the NotCacheKeyAttribute custom attribute to exclude a parameter from being a part of the cache key.

To invalidate a cached method, see InvalidateCacheAttribute and CachingServices.Invalidation.

Constructors

Name Description
CacheAttribute()
CacheAttribute(PortableFormatterConstructorContext)

Properties

Name Description
AbsoluteExpiration

Gets or sets the total duration, in minutes, during which the result of the current method is stored in cache. The absolute expiration time is counted from the moment the method is evaluated and cached.

AutoReload

Determines whether the method calls are automatically reloaded (by re-evaluating the target method with the same arguments) when the cache item is removed from the cache.

IgnoreThisParameter

Determines whether the this instance should be a part of the cache key. The default value of this property is false, which means that by default the this instance is a part of the cache key.

Priority

Gets or sets the priority of the current method.

ProfileName

Gets or sets the name of the CachingProfile that contains the configuration of the current CacheAttribute.

SlidingExpiration

Gets or sets the duration, in minutes, during which the result of the current method is stored in cache after it has been added to or accessed from the cache. The expiration is extended every time the value is accessed from the cache.