Skip to content

Commit f0880a2

Browse files
committed
Disable caching of Comments() action
Adds an OutputCache attribute the the Comments() action, to prevent IE from aggressively caching the comments list. Otherwise IE will only show the comments that were returned in the first request unless you refresh the entire page.
1 parent bbfc0e9 commit f0880a2

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

site/jekyll/getting-started/tutorial.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -402,13 +402,16 @@ namespace ReactDemo.Controllers
402402
Let's also add a new controller action to return the list of comments:
403403

404404
```csharp
405+
[OutputCache(Location = OutputCacheLocation.None)]
405406
public ActionResult Comments()
406407
{
407408
return Json(_comments, JsonRequestBehavior.AllowGet);
408409
}
409410
```
410411

411-
And a corresponding route in `App_Start\RouteConfig.cs`:
412+
The `OutputCache` attribute is used here to prevent IE from caching the ajax request. IE tries to optimize things by assuming that identical requests will return identical responses. Subsequent calls to the Comments action will simply return the cached response from the first call, the result being that the comment list is never updated in IE as new comments are added. When designing a real world API, cache times of API requests should be considered more carefully. For this tutorial it is easiest to simply disable caching.
413+
414+
Finally we add a corresponding route in `App_Start\RouteConfig.cs` to simplify the request URL a bit:
412415

413416
```csharp{12-16}
414417
using System.Web.Mvc;

0 commit comments

Comments
 (0)