how can use server side caching in mvc ?

example is required 

Last updated:7/6/2019 1:18:03 AM

1 Answers

Anonymous User
Anonymous User

If we want to use cache for static contents, then we have to define a few configurations in our application's Web.Config file as below. Here you can see, we have defined the file extension with mime type which needs to be cache. To defining age of caching time, we use 'cacheControlMaxAge' attribute from 'clientCache' and define the time here. For this demonstration, we have used 1 minute.

<system.webServer>

    <staticContent>
      <clear/>
      <clientCache cacheControlMode='UseMaxAge' cacheControlMaxAge='00:01:00' />
      <mimeMap fileExtension='.jpg' mimeType='image/jpg'/>
      <mimeMap fileExtension='.png' mimeType='image/jpg'/>
      <mimeMap fileExtension='.css' mimeType='text/css'/>
      <mimeMap fileExtension='.js' mimeType='text/javascript'/>
    </staticContent>
    <validation validateIntegratedModeConfiguration='false' />
    <modules>
      <remove name='ApplicationInsightsWebTracking' />
      <add name='ApplicationInsightsWebTracking' type='Microsoft.ApplicationInsights.Web.ApplicationInsightsHttpModule, Microsoft.AI.Web' preCondition='managedHandler' />
    </modules>
</system.webServer>

For more information, please follow the given below links :

https://www.mindstick.com/articles/126234/caching-concept-in-asp-dot-net-mvc

Answer