1 Answer

0 votes
by

Application. It enables us to cache the content returned by any controller method so that the same content does not need to be generated each time the same controller method is invoked. Output Caching has huge advantages, such as it reduces server round trips, reduces database server round trips, reduces network traffic etc.

 

Keep the following in mind,

  • Avoid caching contents that are unique per user.
  • Avoid caching contents that are accessed rarely.
  • Use caching for contents that are accessed frequently.
Let's take an example. My MVC application displays a list of database records on the view page so by default each time the user invokes the controller method to see records, the application loops through the entire process and executes the database query. And this can actually decrease the application performance. So, we can advantage of the "Output Caching" that avoids executing database queries each time the user invokes the controller method. Here the view page is retrieved from the cache instead of invoking the controller method and doing redundant work.
 
Cached Content Locations
 
In the above paragraph I said, in Output Caching the view page is retrieved from the cache, so where is the content cached/stored?
 
Please note, there is no guarantee that content will be cached for the amount of time that we specify. When memory resources become low, the cache starts evicting content automatically.
 
OutputCache label has a "Location" attribute and it is fully controllable. Its default value is "Any", however there are the following locations available; as of now, we can use any one.
  1. Any
  2. Client
  3. Downstream
  4. Server
  5. None
  6. ServerAndClient
With "Any", the output cache is stored on the server where the request was processed. The recommended store cache is always on the server very carefully. You will learn about some security related tips in the following "Don't use Output Cache".

Related questions

0 votes
    What is the Difference between session and caching?...
asked Apr 7, 2021 in Education by JackTerrance
0 votes
0 votes
    What is Scaffolding in MVC?...
asked Apr 5, 2021 in Education by JackTerrance
0 votes
    What are the methods of handling an Error in MVC?...
asked Apr 5, 2021 in Education by JackTerrance
0 votes
    What is difference between MVC and Web Forms?...
asked Apr 5, 2021 in Education by JackTerrance
0 votes
    What are the Folders in MVC application solutions?...
asked Apr 5, 2021 in Education by JackTerrance
0 votes
    What is Database First Approach in MVC using Entity Framework?...
asked Apr 5, 2021 in Education by JackTerrance
0 votes
    What is Validation Summary in MVC?...
asked Apr 5, 2021 in Education by JackTerrance
0 votes
    What is Bundling and Minification in MVC?...
asked Apr 5, 2021 in Education by JackTerrance
0 votes
0 votes
0 votes
    Explain the concept of MVC Scaffolding?...
asked Apr 5, 2021 in Education by JackTerrance
0 votes
    Explain the need of display mode in MVC?...
asked Apr 5, 2021 in Education by JackTerrance
...