Improve Boilerplate response caching (#9782)#9783
Improve Boilerplate response caching (#9782)#9783msynk merged 5 commits intobitfoundation:developfrom yasmoradi:9776
Conversation
WalkthroughThe changes update XML documentation and refine logic in caching and rendering components. The modifications include condition changes in cache handling, updates to the context for stream prerendering control, and an adjustment in the rendering logic for pre-rendering based on the new method. Additionally, a new extension method and header setting improvements for sitemap endpoints have been introduced. Changes
Sequence Diagram(s)sequenceDiagram
participant C as Client
participant AR as App.razor
participant HT as HttpRequestExtensions
C->>AR: Send request
AR->>HT: Call DisableStreamPrerendering()
HT-->>AR: Return boolean flag
alt Prerendering Disabled
AR->>AR: Render StreamRenderingDisabledContainer
else Prerendering Enabled
AR->>AR: Render StreamRenderingEnabledContainer
end
sequenceDiagram
participant C as Client
participant AP as AppResponseCachePolicy
participant CM as Cache Middleware
C->>AP: Invoke CacheRequestAsync(context)
AP->>AP: Check (outputCacheTtl > 0)
AP->>Context: Set "DisableStreamPrerendering" flag
AP->>CM: Continue caching process
Assessment against linked issues
Poem
Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media? 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
CodeRabbit Configuration File (
|
There was a problem hiding this comment.
Actionable comments posted: 0
🧹 Nitpick comments (3)
src/Templates/Boilerplate/Bit.Boilerplate/src/Server/Boilerplate.Server.Web/Extensions/HttpRequestExtensions.cs (1)
31-37: LGTM! Consider adding XML documentation.The method logic is correct and aligns with the caching improvements. Consider adding XML documentation to explain the method's purpose and return value.
+ /// <summary> + /// Determines if stream prerendering should be disabled based on caching policy or crawler client status. + /// </summary> + /// <returns>True if stream prerendering should be disabled; otherwise, false.</returns> public static bool DisableStreamPrerendering(this HttpRequest request)src/Templates/Boilerplate/Bit.Boilerplate/src/Server/Boilerplate.Server.Web/Services/AppResponseCachePolicy.cs (1)
93-93: Consider using a constant for the context item key.The string literal "AppResponseCachePolicy__DisableStreamPrerendering" is used in multiple places. Consider extracting it to a constant to prevent typos and improve maintainability.
+ private const string DisableStreamPrerenderingKey = "AppResponseCachePolicy__DisableStreamPrerendering";Then use it in the code:
- context.HttpContext.Items["AppResponseCachePolicy__DisableStreamPrerendering"] = outputCacheTtl > 0 || edgeCacheTtl > 0; + context.HttpContext.Items[DisableStreamPrerenderingKey] = outputCacheTtl > 0 || edgeCacheTtl > 0;src/Templates/Boilerplate/Bit.Boilerplate/src/Server/Boilerplate.Server.Web/Program.Middlewares.cs (1)
205-205: LGTM! Consider using ContentType constants.The addition of the ContentType header is correct and necessary for proper XML handling.
Consider using
Microsoft.Net.Http.Headers.MediaTypeHeaderValue.ApplicationXml.ToString()for better maintainability:-context.Response.Headers.ContentType = "application/xml"; +context.Response.Headers.ContentType = Microsoft.Net.Http.Headers.MediaTypeHeaderValue.ApplicationXml.ToString();
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (5)
src/Templates/Boilerplate/Bit.Boilerplate/src/Server/Boilerplate.Server.Api/Services/AppResponseCachePolicy.cs(3 hunks)src/Templates/Boilerplate/Bit.Boilerplate/src/Server/Boilerplate.Server.Web/Components/App.razor(1 hunks)src/Templates/Boilerplate/Bit.Boilerplate/src/Server/Boilerplate.Server.Web/Extensions/HttpRequestExtensions.cs(1 hunks)src/Templates/Boilerplate/Bit.Boilerplate/src/Server/Boilerplate.Server.Web/Program.Middlewares.cs(1 hunks)src/Templates/Boilerplate/Bit.Boilerplate/src/Server/Boilerplate.Server.Web/Services/AppResponseCachePolicy.cs(3 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (1)
- GitHub Check: build and test
🔇 Additional comments (4)
src/Templates/Boilerplate/Bit.Boilerplate/src/Server/Boilerplate.Server.Web/Components/App.razor (1)
68-68: LGTM! Improved rendering control based on caching policy.The change correctly uses the new
DisableStreamPrerendering()method to determine rendering behavior, considering both caching policy and crawler status.src/Templates/Boilerplate/Bit.Boilerplate/src/Server/Boilerplate.Server.Web/Services/AppResponseCachePolicy.cs (1)
85-91: LGTM! Improved cache TTL condition.The condition change from
!= -1to> 0is more precise and better expresses the intent.src/Templates/Boilerplate/Bit.Boilerplate/src/Server/Boilerplate.Server.Api/Services/AppResponseCachePolicy.cs (1)
95-97: LGTM! Proper conditional compilation for API integration.The stream prerendering context item is correctly wrapped in conditional compilation directives for API integration scenarios.
src/Templates/Boilerplate/Bit.Boilerplate/src/Server/Boilerplate.Server.Web/Program.Middlewares.cs (1)
189-254: LGTM! Well-designed caching strategy.The caching configuration is well-structured with appropriate durations:
- 7 days for static sitemaps
- 5 minutes for dynamic product sitemap
This balances performance with content freshness.
closes #9782
Summary by CodeRabbit
New Features
Documentation
Refactor