سؤال

I'm using custom cache on a page, leaving a timestamp to follow cached versions.

I have

<%@ OutputCache Duration="1200" VaryByParam="None" VaryByCustom="myCache" Location="ServerAndClient" %>

on the page, and the code-behind of Global.asax has (simplified)

Public Overrides Function GetVaryByCustomString(context As HttpContext, arg As String) As String
If (arg = "myCache") Then
   If context.Request.QueryString("Type").ToString() = "1" Then Return "cache-1"
   If context.Request.QueryString("Type").ToString() = "2" Then Return "cache-2"
   If context.Request.Cookies("Type").Value = "1" Then Return "cache-1"
   Return "cache-2"
End If

cache-2 is default state for when no querystring request has been made and cookie doesn't say otherwise. The page saves the cookie with value of Type.

When I call the page with either ?Type=1 or ?Type=2 the page isn't saved to cache - each refresh the timestamp changes.

I found that if I call the page without the Type parameter cache is saved and then exists when I call the page with the parameter as well.

Is there an explanation? Moreover - in Global.asax I couldn't access Response object or file system to log what's happening. Is there a way?

UPDATE

e.g. calling <url>?Type=1, then <url> gives me cache for next calls of <url>?Type=1, but gives same cache for <url>?Type=2.

UPDATE

I now have Return "cache" & context.Request.QueryString("Type"). While sending a request without Type in the querystring gives a cached version of the page, sending Type does not cache, though the result (cache1 or cache2) is the same and page should get cached.

follow up I've found sending Type=3, or anything besides 1 and 2 does cache the page as desired. Page_Load acts upon values 1 & 2 - could there be any connection?

هل كانت مفيدة؟

المحلول

Answers to this question seem to explain a lot. Workaround is a separate question.

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top