From 7f76c5c9c1ed51e08e934f2e04817efa6770a0b8 Mon Sep 17 00:00:00 2001 From: Hamid Reza Mohammadi Date: Sun, 13 Sep 2026 14:56:55 +0330 Subject: [PATCH] caching fixes --- GanjooRazor/Utils/AnonymousPageOutputCachePolicy.cs | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/GanjooRazor/Utils/AnonymousPageOutputCachePolicy.cs b/GanjooRazor/Utils/AnonymousPageOutputCachePolicy.cs index 11f69e16..4b383a27 100644 --- a/GanjooRazor/Utils/AnonymousPageOutputCachePolicy.cs +++ b/GanjooRazor/Utils/AnonymousPageOutputCachePolicy.cs @@ -54,6 +54,16 @@ namespace GanjooRazor.Utils context.AllowCacheStorage = !isPersonalized; context.Tags.Add("ganjoor-public-page"); + // Vary the cache entry by every query string key. Without this, the cache key is + // just the bare path - so /Search and /Simi (which read the actual search/rhythm + // term, poet, category, page number etc. entirely from the query string, not the + // path) would collapse every distinct search onto ONE shared cache entry, and every + // visitor would get back whichever stranger's search happened to be cached. This is + // the same "vary by any query by default" line ASP.NET Core's own DefaultPolicy sets + // - it's not automatic for a standalone custom policy like this one, it has to be set + // explicitly. + context.CacheVaryByRules.QueryKeys = "*"; + // Short TTL: a poem/poet/category edit needs to reach anonymous visitors within // minutes, not be pinned for the site's whole lifetime. Tune per page type later if // needed (e.g. shorter for recently-active pages, longer for old archived poets).