Response cache not working in asp.net core project

Devloper

I try to implement Response cache in asp.net core project but its not working.This is startup.cs

             public void ConfigureServices(IServiceCollection services)
    {
        services.AddResponseCaching();
        services.AddMvc();
    }




      public void Configure(IApplicationBuilder app, IHostingEnvironment env)
    {
         app.UseResponseCaching();

            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
            }

and this is my controller.

    [ResponseCache(Duration = 30)]
public IActionResult Index()
    {
        ViewBag.IsMobile = RequestExtensions.IsMobileBrowser(ContextAccessor.HttpContext.Request);

        return View();
    }

but still cache control header id

              cache-control →no-cache, no-store

Where i am lacking please help.This response cache is not working and i take guidance from Microsoft document

sanmolhec

Beware that for the cache to work must meet a number of requirements:

The request must result in a 200 (OK) response from the server.

The request method must be GET or HEAD.

Terminal middleware, such as Static File Middleware, must not process the response prior to the Response Caching Middleware.

The Authorization header must not be present.

Cache-Control header parameters must be valid, and the response must be marked public and not marked private.

The Pragma: no-cache header/value must not be present if the Cache-Control header is not present, as the Cache-Control header overrides the Pragma header when present. The Set-Cookie header must not be present.

Vary header parameters must be valid and not equal to *.

The Content-Length header value (if set) must match the size of the response body.

...

See this website: aspnet-core-response-cache

And beware also that if the request is being made from Postman disable the option "do not send the cache header".

See this post (image of end post): ASP.Net Core 2.0 - ResponseCaching Middleware - Not Caching on Server

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related