Why is HttpContext.Cache always null?

I have set up a few OutputCache profile pages and confirmed that they are cached with multiple browsers and requests to get a timestamped page that matches all requests. When I try to list HttpContect.Cache it is always empty.

Any ideas what is going on here or where should I look for this information?

Update:

This is not a cache client because multiple browsers see the same response. Here's some code to explain what's going on.

Web.Config Caching Settings

<system.web>
    <caching>
        <outputCacheSettings>
            <outputCacheProfiles>
                <clear/>
                <add name="StaticContent" duration="1200" varyByParam="none"/>
                <add name="VaryByParam" duration="1200" varyByParam="*"/>
            </outputCacheProfiles>
        </outputCacheSettings>
    </caching>
     ...
</system.web>

      

** Action method with caching

[OutputCache(CacheProfile = "StaticContent")]
public ActionResult Index()
{
    return View(new CollaborateModel());
}

      

Code to enumerate cache, yes it is rough, it is defined in controller action method

    var sb = new StringBuilder();

    foreach (KeyValuePair<string, object> item in HttpContext.Cache)
    {
        sb.AppendFormat("{0} : {1}<br />", item.Key, item.Value.ToString());
    }

    ViewData.Add("CacheContents", sb.ToString());

      

HttpContext.Cache is where count is always null, even if the cache is working fine.

+2


source to share


2 answers


Instead of using HttpCache, I ended up with my own caching model for storing datasets in my data access layer. If I were to search for the AD profile of a given username and convert it to a DTO, I would simply put that profile in a rolling DTO of the profile, which I would check before polling AD for information.



0


source


Probably because the page was cached downstream in the client's browser and not on the server.



0


source







All Articles