ASP.NET MVC hits outputcache for every action
Asked Answered
T

2

7

We are running quite a large site build with ASP.NET MVC 3 and AppFabric as a distributed caching solution. We have implemented a custom OutputCacheAdapter to use our AppFabric cluster.

We are seeing that ASP.NET calls the OutputCacheProvider.Get() method for every action, even if that action is NOT decorated with a @OutputCacheAttribute.

That isn't much of a problem if you use the default outputcacheprovider but it is when you are running an outputcacheprovider that resides on seperate machines.

Telluride answered 16/4, 2012 at 12:20 Comment(0)
R
4

It is by design that the the output cache is checked first for a cached copy of the page. If there is a cached copy, it's returned and nothing further is executed. In particular, no controller and no controller action is derived, inspected or executed. This happens only if the page is not cached.

You will need to change your cache provider so that it can quickly determine if a page can potentially be cached. Only if it is a cachable page, then it should go and check the distributed cache. This check cannot based on the OutputCacheAttribute as they are not available during this part of the request processing. Instead, the quick check must be made with the URL, the cookies and other HTML header information.

Rohrer answered 16/4, 2012 at 13:58 Comment(2)
Yeah that sounds like a good explanation. Can't really do much with it though, either accept the performance penalty, go back to the default OutputCacheProvider or provide something like a black or white list for the URLS.Telluride
@Telluride I haven't done it myself but can't you get the route parameters somehow and then use reflection to examine the attributes on the controller/action? It's not ideal but is probably still faster than a network round-trip.Indamine
P
1

You can use Donut Cache outputcache attribute which lets you to define a prefix for output cache keys. So in your custom provider just get/set the cache if cache key starts with your own prefix.

Polyurethane answered 14/4, 2017 at 4:15 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.