Repository navigation
[MVC] Account for CacheTagHelper vary-by key size - #69232
Merged
Merged
Conversation
javiercn
marked this pull request as ready for review
September 14, 2026 10:05
javiercn
requested review from
a team,
Youssef1313,
cincuranet,
davpetr and
rokonec
as code owners
September 14, 2026 10:05
Contributor
There was a problem hiding this comment.
🟡 Changes recommended
Culture-varying keys omit retained culture-string sizes from the estimate.
Get a fresh assessment by requesting another Copilot review.
Pull request overview
Updates MVC CacheTagHelper memory accounting to include retained cache-key string payloads in placeholder and final cache entries.
Changes:
- Adds estimated UTF-16 key-size calculation.
- Applies key size to both cache entries.
- Adds focused unit tests.
File summaries
| File | Summary |
|---|---|
src/Mvc/Mvc.TagHelpers/test/CacheTagKeyTest.cs |
Tests aggregate key-size calculation. |
src/Mvc/Mvc.TagHelpers/test/CacheTagHelperTest.cs |
Tests placeholder and final entry sizes. |
src/Mvc/Mvc.TagHelpers/src/CacheTagHelper.cs |
Includes key size in cache entry sizes. |
src/Mvc/Mvc.TagHelpers/src/Cache/CacheTagKey.cs |
Estimates retained key-string memory. |
Review details
- Files reviewed: 4/4 changed files
- Comments generated: 1
- Review effort level: Lite
💡 Add a code-review agent skill for context-aware, tailored reviews. Learn more in the docs.
Member
Author
|
/azp run aspnetcore-ci |
|
Azure Pipelines: Successfully started running 1 pipeline(s). |
DeagleGross
approved these changes
Sep 28, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #66723
Overview
CacheTagHelperpreviously counted only rendered HTML towardMemoryCacheEntryOptions.Size, omitting the retainedCacheTagKeystrings. This change adds UTF-16 payload accounting for the key to both the temporary placeholder and final cache entries, soCacheTagHelperOptions.SizeLimitbetter reflects retained memory. The change is limited to fourMvc.TagHelpersimplementation/test files and preserves the existing 100 MB default.Design
None. There is no public API, configuration, or default-value change.
The estimate intentionally counts retained string payload rather than attempting to model runtime-specific object and collection overhead. This matches the existing rendered-content accounting, which also counts payload bytes rather than the exact managed object graph.
Implementation
Focused tests cover the two distinct behaviors:
CacheTagKeyTestverifies the aggregate estimate acrossvary-by, user, culture, cookie, header, query, and route strings;CacheTagHelperTestverifies that a concrete header name/value contributes to both actualICacheEntry.Sizeassignments.Outcome
Before the implementation, the faithful mocked
IMemoryCachereproduction reached the cache-entry boundary and failed as expected:The review follow-up test for culture-varying keys also failed before its fix as expected:
After the implementation, focused size tests passed:
The complete affected unit-test project also passed after the review fix:
src/Mvc/build.shis unsupported on this Windows host (mingw64_nt), so validation used the repository's Windowsbuild.cmdpipeline. A broader MVC-area build is not claimed: its prerequisite traversal required unrelated generated assets and an uninitializedMessagePack-CSharpsubmodule.