You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
In-memory cache must be enabled globally for the whole back-end. It is not possible to enable it at the level of individual classes or methods.
129
129
130
-
## Exception handling
130
+
###Exception handling
131
131
132
132
Failures are highly likely if your system is overloaded. Here is how they are handled:
133
133
@@ -136,7 +136,7 @@ Failures are highly likely if your system is overloaded. Here is how they are ha
136
136
137
137
The exception handling policy described above is abstracted by the <xref:PostSharp.Patterns.Caching.Resilience.IExceptionHandlingPolicy> interface and configured by the <xref:PostSharp.Patterns.Caching.Backends.Redis.RedisCachingBackendConfiguration.ExceptionHandlingPolicy> property.
138
138
139
-
## Performance tuning
139
+
###Performance tuning
140
140
141
141
With any level of load, it is recommended to enable cache key compression by assigning the <xref:PostSharp.Patterns.Caching.CachingServices.DefaultKeyBuilder?CachingServices.DefaultKeyBuilder> property to a <xref:PostSharp.Patterns.Caching.Implementation.CacheKeyBuilder> instance with a non-default <xref:PostSharp.Patterns.Caching.Implementation.CacheKeyHashingAlgorithm>.
142
142
@@ -152,31 +152,40 @@ The following <xref:PostSharp.Patterns.Caching.Backends.Redis.RedisCacheDependen
152
152
153
153
Note that you can run a manual cleanup by calling the <xref:PostSharp.Patterns.Caching.Implementation.CachingBackend.CleanUpAsync*?CachingBackend.CleanUpAsync> method. Do not run this method with the default options on a production database; these options are optimized for the cleanup operation's performance and may overload your server.
154
154
155
+
### Monitoring
156
+
157
+
The following metrics are relevant to assess the health of your caching set up:
158
+
159
+
- Number of cache evictions per second. A high number might mean either insufficient caching memory, or ineffective caching strategy - caching things that are not worth it (too many cache misses)
160
+
- Number of cache expirations per second. A high number might mean too small expiration delays
161
+
- Number of warnings per minute in the caching component. A high number means that your system is overloaded.
162
+
163
+
If you want to gather statistics about cache hits and misses, you can do so by implementing a <xref:PostSharp.Patterns.Caching.Implementation.CachingBackendEnhancer> that overrides the <xref:PostSharp.Patterns.Caching.Implementation.CachingBackend.GetItemCore*> and <xref:PostSharp.Patterns.Caching.Implementation.CachingBackend.GetItemAsyncCore*> methods (a `null` return value means a cache miss).
164
+
155
165
## Data schema
156
166
157
167
When dependencies are enabled, <xref:PostSharp.Patterns.Caching.Backends.Redis.RedisCachingBackend> relies on these keys:
2. Item value: `<prefix>:<schema-version>:ver:<hash>:<item-key>` — a list with values: `[<item-value>, <item-sliding-expiration>, <tag0>, <tag1> ... <tagn>]`.
161
-
3. Backward dependencies: `<prefix>:<schema-version>:bdep:<hash>:<dependency-key>` — hash set of `<item-version>:<item-key>`.
162
-
4. Forward dependencies: `<prefix>:<schema-version>:fdep:<hash>:<item-version>:<item-key>` — list of `<item-key>`.
2. Item value: `<prefix>:<schema-version>:{<item-key>}:val:<item-version>` — a list with values: `[<item-value>, <item-sliding-expiration>, <tag0>, <tag1> ... <tagn>]`.
171
+
3. Backward dependencies: `<prefix>:<schema-version>:{<dependency-key>}:bdep` — hash set of `<item-version>:<item-key>`.
172
+
4. Forward dependencies: `<prefix>:<schema-version>:{<item-key>}:fdep:<item-version>` — list of `<dependency-key>`.
163
173
164
174
When dependencies are disabled, only the item value record is used.
165
175
166
176
In this description, elements between angle brackets are placeholders and mean the following:
167
177
168
-
-`<item-key>` is the cache key (as generated by <xref:PostSharp.Patterns.Caching.Implementation.CacheKeyBuilder>), where `{`and `}` are escaped.
178
+
-`<item-key>` is the cache key (as generated by <xref:PostSharp.Patterns.Caching.Implementation.CacheKeyBuilder>), where `{`, `}`and `:` have been escaped.
169
179
-`<item-value>` is the serialized cache value.
170
180
-`<prefix>` is the value of the <xref:PostSharp.Patterns.Caching.Backends.Redis.RedisCachingBackendConfiguration.Prefix> property.
171
181
-`<schema-version>` is the version of the data schema internal to <xref:PostSharp.Patterns.Caching.Backends.Redis.RedisCachingBackend>.
172
-
-`<hash>` is a 16-bit hash of `<item-key>` surrounded with curly brackets, e.g. `{Aj4}`, unless the <xref:PostSharp.Patterns.Caching.Backends.Redis.RedisCachingBackendConfiguration.Prefix> property already contains a sharding hash (which is not recommended). This hash ensures that all keys corresponding to the same cache item reside in the same Redis node.
173
182
-`<item-version>` is a randomly generated item version.
174
-
-`<dependency-key>` is either a dependency key or a cache item key, when the cache item is itself a dependency (recursive dependencies), where `{`and `}` are escaped.
183
+
-`<dependency-key>` is either a dependency key or a cache item key, when the cache item is itself a dependency (recursive dependencies), where `{`, `}`and `:` have been escaped.
175
184
176
185
## Clearing the cache
177
186
178
187
To remove all cache keys, you can:
179
188
180
189
* Use the `FLUSHDB` Redis command to delete all keys in the selected database, even those that don’t match the prefix.
181
190
* Use the `SCAN <prefix>:*` command to identify all keys, then use `DEL` for each key.
182
-
* Use the <xref:PostSharp.Patterns.Caching.Implementation.CachingBackend.ClearAsync*> method, which does a `SCAN <prefix>:<schema-version>:*` command, then `DEL` for each key.
191
+
* Use the <xref:PostSharp.Patterns.Caching.Implementation.CachingBackend.ClearAsync*> method, which does a `SCAN <prefix>:<schema-version>:*` command, then `UNLINK` for each key.
0 commit comments