We have a problem with output caching used within a web farm environment which cannot be replicated in a single node situation. An un-cached page has an un-cached parent user control which has child user controls which are cached. The time to cache is set by setting the PartialCachingAttribute on the user control's class declaration and then the VaryByCustom string is set programmatically in the user control's OnInit event. There is a gobal setting for toggling caching and a block of code which checks for a required list of query string values from the Request object before caching is attempted. GetVaryByCustomString(...) is overloaded in the Global.asax file.
The single node version correctly displays the child user control content within the parent user control but the web farm content caches incorrectly - it mixes up cached items from different calls.
It seems that the output caching mechanism is not working in the web farm scenario. Any ideas?
`<`PartialCaching(600)`>` _
Partial Public Class classname
Protected Overrides Sub OnInit(ByVal e As System.EventArgs)
Me.CachePolicy.Cached = False
'only do caching if global setting is on - elided this code
'only do the caching if the call for this control has the correct params - elided this code
If (Me.CachePolicy.SupportsCaching) Then
Me.CachePolicy.VaryByParams("none") = True
Me.CachePolicy.SetVaryByCustom("MyCacheKey")
Me.CachePolicy.Cached = True
End If
MyBase.OnInit(e)
End Sub
...
End Class
Public Overrides Function GetVaryByCustomString(ByVal context As System.Web.HttpContext, ByVal custom As String) As String
Try
Select Case custom
Case "MyCacheKey"
'only do the caching if the call has the correct params - elided this code
If ...
Return String.Format("{0}_{1}", custom, myUniqueString)
Else
'return a random key otherwise we will have only one cache item for non-captured calls
Return String.Format("{0}_{1}", custom, Guid.NewGuid().ToString)
End If
End Select
Return MyBase.GetVaryByCustomString(context, custom)
Catch ex As ApplicationException
Return Guid.NewGuid().ToString
End Try
End Function