开发者

Why is the HttpContext.Cache count always zero?

I set up a few pages with OutputCache profiles and confirmed that they are being cached by using multiple browsers and requests to retrieve the page with a timestamp which matched across all requests. When I try to enumerate the HttpContect.Cache it is always empty.

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

Update:

It's not client cache because multiple browsers are seeing the same response. Here is a bit of code to explain what's happening.

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 the cache, yep it's rough, an this is defined in a controller action method

    var sb = new StringBuilder();

    foreach (KeyValuePair<string, object> item in HttpContext.Cache)
    {
        sb.AppendFormat("{0} : {1}<br /&g开发者_运维技巧t;", item.Key, item.Value.ToString());
    }

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

The HttpContext.Cache is where the count is always null, even though the cache seems to be working fine.


That's probably because the page has been cached downstream on the client browser and not on the server.


Instead of using the HttpCache I ended up rolling my own caching model for holding datasets in my Data Access layer. If I was looking up the AD profile of a given username and converting it to a DTO then I just put that profile in a rolling collection of profile DTOs that I would check before polling AD for the information.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜