Search code examples
asp.netcachinghttp-caching

HttpRuntime.Cache in global.asax is always empty


I have a series of cached objects cached in this way

HttpRuntime.Cache.Insert(....)

I am trying to use a varyByCustom declaration for a user control, and using this cached object to return a value in global.asax

Public Overrides Function GetVaryByCustomString(context As HttpContext, arg As String) As String
    If arg = "getCache" Then
        Return HttpRuntime.Cache.Get("mainMenu_added")
    End If
end function

I am getting an empty record every time though.

I have checked elsewhere and the cache key does exist, but seems inaccessible in global.asax?


Solution

  • Argh. It was something I had done wrong!

    The control I was trying to refresh was nested in another control which was caching longer!

    Grrr. That is a really annoying "feature" of asp.net!