Open sandboxFocus

Interface ICachingService

Represents a cache: the backend that stores the items, the key builder that computes their keys, the caching profiles, and the operations that the caching aspects call. The default implementation is CachingService.

Namespace: PostSharp.Patterns.Caching
Assembly: PostSharp.Patterns.Caching.dll
Syntax
public interface ICachingService
Remarks

A class receives an ICachingService from a dependency injection container when its assembly, its declaring type or a base type has a CacheConfigurationAttribute whose UseDependencyInjection property is true. Otherwise, the cached methods use DefaultService.

The formatters (CachingServices.Formatters) and the caching context (CurrentContext) are shared by all the services of the process.

Properties

Name Description
Backend

Gets or sets the backend that stores the cached items.

KeyBuilder

Gets or sets the key builder that computes the keys of the cached items.

Profiles

Gets the caching profiles (CachingProfile) of the methods cached by this service.

Methods

Name Description
GetOrAdd(MethodInfo, string, Type, CacheItemConfiguration, Func<object>, LogSource)

Gets a value from the cache or, when the cache has no item for the key, evaluates the value, adds it to the cache and returns it. The CacheAttribute aspect calls this method.

GetOrAddAsync(MethodInfo, string, Type, CacheItemConfiguration, Func<Task<object>>, LogSource, CancellationToken)

Asynchronously gets a value from the cache or, when the cache has no item for the key, evaluates the value, adds it to the cache and returns it. The CacheAttribute aspect calls this method for asynchronous methods.

Invalidate(ICacheDependency)

Invalidates a cache dependency given as an ICacheDependency, i.e. removes all cache items that are dependent on this dependency.

Invalidate(object)

Invalidates a cache dependency given an object, i.e. removes all cached items that are dependent on that object.

Invalidate(MethodInfo, object, params object[])

Removes a method call result from the cache, using the MethodInfo that represents the method, the instance and the arguments of the method call. The InvalidateCacheAttribute aspect calls this method.

Invalidate(string)

Invalidates a cache dependency given as string, i.e. removes all cache items that are dependent on this dependency key.

InvalidateAsync(ICacheDependency)

Asynchronously invalidates a cache dependency given as an ICacheDependency, i.e. removes all cache items that are dependent on this dependency.

InvalidateAsync(object)

Asynchronously invalidates a cache dependency given an object, i.e. removes all cached items that are dependent on that object.

InvalidateAsync(MethodInfo, object, params object[])

Asynchronously removes a method call result from the cache, using the MethodInfo that represents the method, the instance and the arguments of the method call. The InvalidateCacheAttribute aspect calls this method for asynchronous methods.

InvalidateAsync(string)

Asynchronously invalidates a cache dependency given as string, i.e. removes all cache items that are dependent on this dependency key.

See Also