0

I'm currently using the OutputCacheAttribute (in System.Web.Mvc) on an action:

[ChildActionOnly]
[OutputCache(Duration = 24 * 60 * 60)] // Cache for 24 hours
public ContentResult Render(string json, string pagePublished)
{

After the first page load it caches the output and holds it. It sometimes stays cached for hours, sometimes minutes.

I use this action on multiple pages, so first I thought it might have something to do with that. But I've tried to just cache one page and see if it holds, it does not. I've tried to cache a lot of pages and it sometimes holds for hours.

Anyone have an idea about what could be wrong?

EDIT:

The w3wp process uses huge amounts of RAM (this is by design and not a problem) there are still free RAM (about 5gb) for it to allocate. I have built another action that gets the current size of the httpcontext cache. This amounts to about 1350000 bytes. So there should not be a problem with memory.

I also have a problem with MemoryCache which also evicts items at random (Amounts to about 8530000 bytes.)

EDIT2:

It seems like it's saving the output from the action in both MemoryCache and httpcontext cache.

slinzerthegod
  • 615
  • 6
  • 17

1 Answers1

0

There is no guarantee that content will be cached for the amount of time that you specify. When memory resources become low, the cache starts evicting content automatically.

James
  • 80,725
  • 18
  • 167
  • 237
  • Free memory is not a problem. – slinzerthegod Jan 09 '13 at 16:17
  • @slinzerthegod Point being, the `duration` property is not set in stone, treat it more of a *recommended* cache time. – James Jan 09 '13 at 16:30
  • If there is 5GB of free memory on the server it shouldn't be a problem? – slinzerthegod Jan 09 '13 at 16:40
  • I would have thought so, you don't appear to be setting the `Location` property of your cache therefore it could be stored anywhere (client/server/proxy server etc.). Obviously, different locations have different effects on what causes the cache to clear. Try switching it to `OutputCacheLocation.Server` and see if it lasts the specified duration (I assume it will). – James Jan 09 '13 at 18:04
  • You can't set Location for a ChildAction. As you can see here: http://stackoverflow.com/questions/6410431/outputcache-attribute-on-clientside-with-partial-pages – slinzerthegod Jan 10 '13 at 08:38