PostSharp6.1/API Reference/Post­Sharp.​Patterns.​Caching Namespace/Caching­Services Class/Caching­Services Methods/Caching­Services.​Suspend­Dependency­Propagation Method

CachingServices.SuspendDependencyPropagation Method

Temporarily suspends propagation of dependencies from subsequently called methods to the caller method.

Namespace:  PostSharp.Patterns.Caching
Assembly:  PostSharp.Patterns.Caching (in PostSharp.Patterns.Caching.dll) Version: 6.1.23.0 (6.1.23.0)
Syntax
C#
public static IDisposable SuspendDependencyPropagation()

Return Value

Type: IDisposable
IDisposable representation of the suspension. Disposing this object resumes the normal dependency propagation.
Remarks

By default, calling a cached method while another CachingContext is active automatically adds the former as a dependency of the later. Since the CurrentContext is stored in an AsyncLocal<T> variable, it may be inadvertently used after the method call associated with it had already ended. This can happen, for example, when method calls [!:System.Threading.Task.Run] and does not depend on the resulting [!:System.Threading.Task].

This context leak does not break correctness but may lead to unnecessary dependency invalidations. Therefore it is recommended to use this method when calling asynchronous code in the context of cached methods and not being dependent on its result.

See Also