Skip to content

Commit eb4daf3

Browse files
committed
feat: add settings file and update caching policies for Tips page
1 parent 1e7e248 commit eb4daf3

File tree

3 files changed

+17
-13
lines changed

3 files changed

+17
-13
lines changed

.aspire/settings.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"appHostPath": "../AppHost/AppHost.csproj"
3+
}

Web/Pages/Tips/Index.cshtml.cs

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,15 @@
66

77
namespace Web.Pages.Tips;
88

9-
[OutputCache(PolicyName = "SearchResults")]
9+
// Disable output caching for this page to prevent form state caching issues
10+
// We'll implement data-level caching in the service layer instead
1011
public class IndexModel : BasePageModel
1112
{
1213
private readonly IContentService _contentService;
13-
private readonly ILogger<IndexModel> _logger; // Use default cache duration for tips list (6 hours) since new tips are added infrequently
14-
// protected override int CacheDurationSeconds => base.CacheDurationSeconds; // 6 hours default
14+
private readonly ILogger<IndexModel> _logger;
15+
16+
// Disable page-level caching to prevent form state issues
17+
protected override bool AllowCaching => false;
1518

1619
public IndexModel(IContentService contentService, ILogger<IndexModel> logger)
1720
{
@@ -36,13 +39,9 @@ public IndexModel(IContentService contentService, ILogger<IndexModel> logger)
3639

3740
public async Task<IActionResult> OnGetAsync()
3841
{
39-
// For search results, prevent aggressive browser caching
40-
if (!string.IsNullOrEmpty(Search) || !string.IsNullOrEmpty(Category) ||
41-
!string.IsNullOrEmpty(Tag) || !string.IsNullOrEmpty(Difficulty) || PageNumber > 1)
42-
{
43-
Response.Headers.CacheControl = "no-cache, must-revalidate";
44-
Response.Headers.Pragma = "no-cache";
45-
}
42+
// Set cache headers to prevent browser caching of the HTML form state
43+
Response.Headers.CacheControl = "no-cache, must-revalidate";
44+
Response.Headers.Pragma = "no-cache";
4645

4746
try
4847
{
@@ -56,6 +55,8 @@ public async Task<IActionResult> OnGetAsync()
5655
PageSize = 12
5756
};
5857

58+
Console.WriteLine($"Searching tips with: Category={Category}, Tag={Tag}, Search={Search}, Difficulty={Difficulty}, Page={PageNumber}");
59+
5960
var searchResult = await _contentService.SearchTipsAsync(request);
6061

6162
// Get filter options

Web/Program.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -111,12 +111,12 @@
111111
.Expire(TimeSpan.FromDays(3)) // Cache tips for 3 days
112112
.Tag("outputcache", "tips", "content")); // Add tags for better organization
113113

114-
// Policy for search results - shorter cache for dynamic filtering
114+
// Policy for search results - varies by all filter parameters for proper form state
115115
options.AddPolicy("SearchResults", builder =>
116116
builder.Cache()
117117
.SetVaryByHost(true)
118118
.SetVaryByQuery("category", "tag", "search", "difficulty", "pageNumber")
119-
.Expire(TimeSpan.FromMinutes(5)) // Cache search results for 5 minutes
119+
.Expire(TimeSpan.FromSeconds(30)) // Very short cache for better user experience
120120
.Tag("outputcache", "search", "tips")); // Add tags for better organization
121121

122122
// Policy for frequently updated content - extended to 6 hours minimum
@@ -160,7 +160,7 @@
160160
app.UseRewriter(options);
161161

162162
// Configure the HTTP request pipeline.
163-
if (!app.Environment.IsDevelopment())
163+
if (true || !app.Environment.IsDevelopment())
164164
{
165165
app.UseExceptionHandler("/Error");
166166
app.UseHsts();

0 commit comments

Comments
 (0)