Response cache does not work on the following method which returns view containing a form element.If the form element is removed from the view then response cache works. why it is happening?
```
[Route("Contact")]
[ResponseCache(Duration = 3600)] //Does not working for this method
public IActionResult Contact()
{
return View();
}
[HttpPost]
[Route("Contact")]
public IActionResult Contact(ContactViewModel contactViewModel, IFormFile attachment)
{
//Necessary opertaion goes here
return
View(contactViewModel);
}
```
Look at the response headers. Is this happening because the form has anti-forgery enabled which always sets no-cache headers?
@Tratcher Yes! anti-forgery was enabled and that's why response cache was not working..My question is why response cache does not work when anti-forgery in enabled?
The anti-forgery token in the form is attached to a cookie and neither should be cached or else they could get out of sync.
Most helpful comment
The anti-forgery token in the form is attached to a cookie and neither should be cached or else they could get out of sync.