Builds cache item keys and dependency keys.
Implements
Namespace: PostSharp.Patterns.Caching.Implementation
Assembly: PostSharp.Patterns.Caching.dll
Syntax
public class CacheKeyBuilder : IDisposableRemarks
A method key is made of the declaring type, the method name and its generic arguments, the this instance (unless
IgnoreThisParameter is set) and, for each argument, the parameter type and the formatted value. Parameters annotated
with NotCacheKeyAttribute keep their type, but their value is replaced
by the * placeholder. Objects are formatted by the formatters of CachingServices.Formatters,
which fall back to ToString().
The key builder in use is DefaultKeyBuilder. To change the maximal key length or to compress long keys by hashing
them, assign a new instance created with the appropriate constructor; key compression is recommended with the Redis backend. To change how
keys are built, derive a class and override BuildMethodKey(MethodInfo, IList<object>, object), BuildDependencyKey(object), or the Append methods they use.
Constructors
| Name | Description |
|---|---|
| CacheKeyBuilder() | Initializes a new instance of the CacheKeyBuilder class with a default maximal key length of 2048 characters and no key compression. |
| CacheKeyBuilder(int) | Initializes a new instance of the CacheKeyBuilder class and specifies the maximal key length and no key compression. |
| CacheKeyBuilder(int, CacheKeyHashingAlgorithm, int) | Initializes a new instance of the CacheKeyBuilder class and specifies the maximal key length and compressing threshold. |
Properties
| Name | Description |
|---|---|
| HashingAlgorithm | Gets the algorithm used to compress the key if its length is above KeyCompressingThreshold. |
| IgnoredParameterSentinel | Gets a sentinel object that means that the parameter is not a part of the cache key, and should be ignored. |
| KeyCompressingThreshold | Gets the length above which a key will be compressed if HashingAlgorithm is not None. |
| MaxKeySize | Gets the maximal number of characters in cache keys. |
Methods
| Name | Description |
|---|---|
| AppendArgument(UnsafeStringBuilder, Type, object) | Appends a method argument to an UnsafeStringBuilder. To avoid ambiguities between different overloads of the same method, the default implementation appends both the parameter type and the value key. |
| AppendMethod(UnsafeStringBuilder, MethodInfo) | Appends the method name and generic arguments to an UnsafeStringBuilder. |
| AppendObject(UnsafeStringBuilder, object) | Appends a string representing an object to an UnsafeStringBuilder. |
| AppendType(UnsafeStringBuilder, Type) | Appends a Type name to an UnsafeStringBuilder. |
| BuildDependencyKey(object) | Builds a dependency key for a given object. |
| BuildMethodKey(MethodInfo, IList<object>, object) | Builds a cache key for a given method call. |
| CompressKey(UnsafeStringBuilder, bool, int) | Compresses the key if necessary. |
| Dispose() | |
| Dispose(bool) | Disposes the current object. |
| GetCachedMethodInfo(MethodInfo) | Gets the CachedMethodInfo for a given MethodInfo. |
| HashBuffer(ReadOnlySpan<byte>) | Hashes a buffer using HashingAlgorithm. |