Asp.net 自定义缓存不缓存查询字符串
我在页面上使用自定义缓存,留下一个时间戳来跟踪缓存的版本 我有Asp.net 自定义缓存不缓存查询字符串,asp.net,caching,query-string,global-asax,outputcache,Asp.net,Caching,Query String,Global Asax,Outputcache,我在页面上使用自定义缓存,留下一个时间戳来跟踪缓存的版本 我有 <%@ OutputCache Duration="1200" VaryByParam="None" VaryByCustom="myCache" Location="ServerAndClient" %> cache-2是未发出querystring请求且cookie没有说明其他情况时的默认状态。页面将保存值为Type的cookie 当我使用?Type=1或?Type=2调用页面时,页面不会保存到缓存中-每次刷新时间
<%@ OutputCache Duration="1200" VaryByParam="None" VaryByCustom="myCache" Location="ServerAndClient" %>
cache-2
是未发出querystring请求且cookie没有说明其他情况时的默认状态。页面将保存值为Type
的cookie
当我使用?Type=1
或?Type=2
调用页面时,页面不会保存到缓存中-每次刷新时间戳都会更改
我发现,如果我调用不带的页面,类型
参数缓存会被保存,然后在调用带参数的页面时也会存在
有什么解释吗?此外,在Global.asax中,我无法访问Response
对象或文件系统来记录正在发生的事情。有办法吗
更新
e、 g.调用?Type=1
,然后
为?Type=1
的下一次调用提供缓存,但为?Type=2
提供相同的缓存
更新
现在我有了返回“cache”和context.Request.QueryString(“Type”)
。在querystring中发送不带Type
的请求时,会给出页面的缓存版本,但发送Type
不会缓存,尽管结果(cache1
或cache2
)是相同的,页面应该被缓存
跟进
我发现发送Type=3
,或者除1
和2
之外的任何内容都会根据需要缓存页面<代码>页面加载作用于值1
和2
-是否存在任何联系?答案似乎解释了很多。解决方法是一个单独的问题
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