Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

OutputCache in ASP.Net Core MVC

I Have an module in one application that loads the list of items in dropdown depending if these items are set true of checked in system settings.

When certain item is set to yes, this item should automatically be part of the dropdown choices. This PERFECTLY WORKS in Google Chrome and other browsers but NOT in Internet Explorer.

I thought of cache problem since i experience the same in previous projects.

i just include this above the action in controller

[OutputCache(NoStore = true)]

Tried the same now in ASP.Net Core MVC

But having a "namespace "OutputCacheAttribute" could not be found.

  1. is this no longer part in core mvc?
  2. tried responseCache which is available, but does not work also, is responsecache the alternative incore mvc? what's the difference?
like image 818
rickyProgrammer Avatar asked Aug 24 '17 04:08

rickyProgrammer


People also ask

What is OutputCache MVC?

The output cache enables you to cache the content returned by a controller action. That way, the same content does not need to be generated each and every time the same controller action is invoked. Imagine, for example, that your ASP.NET MVC application displays a list of database records in a view named Index.

What is the use of Outputcacheattribute in MVC?

In ASP.NET MVC, there is an OutputCache filter attribute that you can apply and this is the same concept as output caching in web forms. The output cache enables you to cache the content returned by a controller action. Output caching basically allows you to store the output of a particular controller in the memory.

Where is output cache stored in MVC?

There is a property of the OutputCache attribute 'Location' with following possible values: Any (Default): Content is cached in three locations: the web server, any proxy servers, and the web browser. Client: Content is cached on the web browser. Server: Content is cached on the web server.

What is Varybyparam OutputCache?

It allows varying the cached output by GET query string or form POST parameters. For instance, you can vary the user-control output to the cache by specifying the user-control name along with either a query string or a form POST parameter. For more information, see Caching Multiple Versions of User Control Output.


Video Answer


1 Answers

You can use

[ResponseCache(VaryByHeader = "User-Agent", Duration = 30)]
public IActionResult About2()
{
    return Ok();
}

MSDN link

like image 94
Calabonga Avatar answered Oct 12 '22 10:10

Calabonga