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
Current Time Inside Cache Tag Helper: @DateTime.Now
41
+
</cache>
42
+
```
43
+
44
+
### `enabled`
45
+
46
+
| Attribute type | Examples | Default |
47
+
| --------------- | --------------- | :-----: |
32
48
| Boolean |`true`, `false`|`true`|
33
49
34
50
`enabled` determines if the content enclosed by the Cache Tag Helper is cached. The default is `true`. If set to `false`, the rendered output is **not** cached.
Sets the time that a cache entry should be evicted if its value hasn't been accessed.
100
+
`priority` provides cache eviction guidance to the built-in cache provider. The web server evicts `Low` cache entries first when it's under memory pressure.
Current Time Inside Cache Tag Helper: @DateTime.Now
91
107
</cache>
92
108
```
93
109
94
-
### vary-by-header
110
+
The `priority` attribute doesn't guarantee a specific level of cache retention. `CacheItemPriority` is only a suggestion. Setting this attribute to `NeverRemove` doesn't guarantee that cached items are always retained. See the topics in the [Additional Resources](#additional-resources) section for more information.
The Cache Tag Helper is dependent on the [memory cache service](xref:performance/caching/memory). The Cache Tag Helper adds the service if it hasn't been added.
99
113
100
-
`vary-by-header` accepts a comma-delimited list of header values that trigger a cache refresh when they change.
114
+
### `vary-by`
101
115
102
-
The following example monitors the header value `User-Agent`. The example caches the content for every different `User-Agent` presented to the web server:
116
+
| Attribute type | Example |
117
+
| -------------- | -------- |
118
+
| String |`@Model`|
119
+
120
+
`vary-by` allows for customization of what data is cached. When the object referenced by the attribute's string value changes, the content of the Cache Tag Helper is updated. Often, a string-concatenation of model values are assigned to this attribute. Effectively, this results in a scenario where an update to any of the concatenated values invalidates the cache.
121
+
122
+
The following example assumes the controller method rendering the view sums the integer value of the two route parameters, `myParam1` and `myParam2`, and returns the sum as the single model property. When this sum changes, the content of the Cache Tag Helper is rendered and cached again.
`vary-by-query` accepts a comma-delimited list of <xref:Microsoft.AspNetCore.Http.IQueryCollection.Keys*> in a query string (<xref:Microsoft.AspNetCore.Http.HttpRequest.Query*>) that trigger a cache refresh when the value of any listed key changes.
151
+
`vary-by-cookie` accepts a comma-delimited list of cookie names that trigger a cache refresh when the cookie values change.
117
152
118
-
The following example monitors the values of `Make` and `Model`. The example caches the content for every different `Make` and `Model` presented to the web server:
153
+
The following example monitors the cookie associated with ASP.NET Core Identity. When a user is authenticated, a change in the Identity cookie triggers a cache refresh:
Current Time Inside Cache Tag Helper: @DateTime.Now
123
158
</cache>
124
159
```
160
+
161
+
### `vary-by-culture`
125
162
126
-
### vary-by-route
127
-
128
-
| Attribute Type | Examples |
129
-
| -------------- | -------------------- |
130
-
| String |`Make`, `Make,Model`|
163
+
| Attribute type | Examples | Default |
164
+
| -------------- | --------------- | :-----: |
165
+
| Boolean |`true`, `false`|`false`|
131
166
132
-
`vary-by-route` accepts a comma-delimited list of route parameter names that trigger a cache refresh when the route data parameter value changes.
167
+
`vary-by-culture` varys the cached result by request culture. Setting the attribute to `true` means the result is varied by <xref:System.Globalization.CultureInfo.CurrentCulture%2A?displayProperty=nameWithType> and <xref:System.Globalization.CultureInfo.CurrentUICulture%2A?displayProperty=nameWithType>.
`vary-by-cookie` accepts a comma-delimited list of cookie names that trigger a cache refresh when the cookie values change.
183
+
`vary-by-header` accepts a comma-delimited list of header values that trigger a cache refresh when they change.
159
184
160
-
The following example monitors the cookie associated with ASP.NET Core Identity. When a user is authenticated, a change in the Identity cookie triggers a cache refresh:
185
+
The following example monitors the header value `User-Agent`. The example caches the content for every different `User-Agent` presented to the web server:
Current Time Inside Cache Tag Helper: @DateTime.Now
165
190
</cache>
166
191
```
167
192
168
-
### vary-by-user
193
+
### `vary-by-query`
169
194
170
-
| Attribute Type | Examples | Default|
171
-
| ---------------| --------------- |------- |
172
-
|Boolean|`true`, `false`|`true`|
195
+
| Attribute type | Examples |
196
+
| -------------- | -------------------- |
197
+
|String|`Make`, `Make,Model`|
173
198
174
-
`vary-by-user` specifies whether or not the cache resets when the signed-in user (or Context Principal) changes. The current user is also known as the Request Context Principal and can be viewed in a Razor view by referencing `@User.Identity.Name`.
199
+
`vary-by-query` accepts a comma-delimited list of <xref:Microsoft.AspNetCore.Http.IQueryCollection.Keys*>in a query string (<xref:Microsoft.AspNetCore.Http.HttpRequest.Query*>) that trigger a cache refresh when the value of any listed key changes.
175
200
176
-
The following example monitors the current logged in user to trigger a cache refresh:
201
+
The following example monitors the values of `Make` and `Model`. The example caches the content for every different `Make` and `Model` presented to the web server:
177
202
178
203
```cshtml
179
-
<cache vary-by-user="true">
204
+
<cache vary-by-query="Make,Model">
180
205
Current Time Inside Cache Tag Helper: @DateTime.Now
181
206
</cache>
182
207
```
183
208
184
-
Using this attribute maintains the contents in cache through a sign-in and sign-out cycle. When the value is set to `true`, an authentication cycle invalidates the cache for the authenticated user. The cache is invalidated because a new unique cookie value is generated when a user is authenticated. Cache is maintained for the anonymous state when no cookie is present or the cookie has expired. If the user is **not** authenticated, the cache is maintained.
185
-
186
-
### vary-by
209
+
### `vary-by-route`
187
210
188
-
| Attribute Type|Example|
189
-
| -------------- | -------- |
190
-
| String |`@Model`|
211
+
| Attribute type|Examples |
212
+
| -------------- | --------------------|
213
+
| String |`Make`, `Make,Model`|
191
214
192
-
`vary-by` allows for customization of what data is cached. When the object referenced by the attribute's string value changes, the content of the Cache Tag Helper is updated. Often, a string-concatenation of model values are assigned to this attribute. Effectively, this results in a scenario where an update to any of the concatenated values invalidates the cache.
215
+
`vary-by-route` accepts a comma-delimited list of route parameter names that trigger a cache refresh when the route data parameter value changes.
193
216
194
-
The following example assumes the controller method rendering the view sums the integer value of the two route parameters, `myParam1` and `myParam2`, and returns the sum as the single model property. When this sum changes, the content of the Cache Tag Helper is rendered and cached again.
`priority` provides cache eviction guidance to the built-in cache provider. The web server evicts `Low` cache entries first when it's under memory pressure.
241
+
`vary-by-user` specifies whether or not the cache resets when the signed-in user (or Context Principal) changes. The current user is also known as the Request Context Principal and can be viewed in a Razor view by referencing `@User.Identity.Name`.
224
242
225
-
Example:
243
+
The following example monitors the current logged in user to trigger a cache refresh:
226
244
227
245
```cshtml
228
-
<cache priority="High">
246
+
<cache vary-by-user="true">
229
247
Current Time Inside Cache Tag Helper: @DateTime.Now
230
248
</cache>
231
249
```
232
250
233
-
The `priority` attribute doesn't guarantee a specific level of cache retention. `CacheItemPriority` is only a suggestion. Setting this attribute to `NeverRemove` doesn't guarantee that cached items are always retained. See the topics in the [Additional Resources](#additional-resources) section for more information.
234
-
235
-
The Cache Tag Helper is dependent on the [memory cache service](xref:performance/caching/memory). The Cache Tag Helper adds the service if it hasn't been added.
251
+
Using this attribute maintains the contents in cache through a sign-in and sign-out cycle. When the value is `true`, an authentication cycle invalidates the cache for the authenticated user. The cache is invalidated because a new unique cookie value is generated when a user is authenticated. Cache is maintained for the anonymous state when no cookie is present or the cookie has expired. If the user is **not** authenticated, the cache is maintained.
0 commit comments