You can use OutputCacheAttribute to control the server and / or browser caching for specific actions or all actions in the controller.
Disable for all actions in the controller
[OutputCacheAttribute(VaryByParam = "*", Duration = 0, NoStore = true)] // will be applied to all actions in MyController, unless those actions override with their own decoration public class MyController : Controller { // ... }
Disable for a specific action:
public class MyController : Controller { [OutputCacheAttribute(VaryByParam = "*", Duration = 0, NoStore = true)]
If you want to apply the default caching strategy to all actions in all controllers, you can add a global action filter by editing your global.asax.cs and looking for the RegisterGlobalFilters method. This method is added to the default MVC project project template.
public static void RegisterGlobalFilters(GlobalFilterCollection filters) { filters.Add(new OutputCacheAttribute { VaryByParam = "*", Duration = 0, NoStore = true, });
This will cause the OutputCacheAttribute application to be listed above for each action that will disable server and browser caching. You can still override this cache by adding OutputCacheAttribute to specific actions and controllers.
HackedByChinese Oct 18 '12 at 6:22 2012-10-18 06:22
source share