Question 70


1.5.2 Question

Multiple Choices

You are creating a solution in which the majority of the application is dynamic, but some areas can be cached for a long time. What kind of approach would you take? (Choose all that apply.)

  • A. Data caching
  • B. Donut hole caching
  • C. Donut caching
  • D. Windows AppFabric caching

Answer:

BC
Explanation
A. Incorrect: Although data caching can add some support in a highly dynamic situation, it does not support the capability to have long-term caching.
B. Correct: Donut hole caching provides the ability to cache parts of each page.
C. Correct: Donut caching is another approach that gives the ability to cache parts of the application.
D. Incorrect: AppFabric caching would provide some support in a highly dynamic situation, but it does not suit the need to store some of the page output.


Page Output Caching
[OutputCache(Duration=120, VaryByParam="Name", Location="ServerAndClient")] Public ActionResult Index() {
Return View(modelData);
}
This code sets the response headers so the browser will know to go to its local cache for the next 120 seconds. The Duration setting represents the time, in seconds, that the page output should be cached. Due to the Location setting in the attribute, any other browser call going to this URL will also get this same server-cached output.
OutputCacheAttribute
Donut caching is a server-side technology that caches an entire page other than the pieces of dynamic content—the donut holes.Although ASP.NET Web Forms supports donut caching through the Substitution control, the Razor Engine does not offer support for donut caching. However, because ASP.NET MVC 4 is built on top of ASP.NET, you can still use the Substitution APIs through the HttpResponse.WriteSubstitution method by creating an MVC helper.
Donut hole caching Caches only select portions of the page while keeping the rest of the page dynamic. Donut hole caching is supported by creating the partial view that will be cached.
[ChildActionOnly]
[OutputCache(Duration=60)]
public ActionResult ProductsChildAction()
{
ViewBag.Products = Model.GetProducts();
return View();
}
Background: Web farm, or where sessions occur over many servers, each server would have to rerun the page to add it to their local cache.
Distrbuted Caching: create data on one application server and share it with the other servers
Windows Server AppFabric: Provides a set of extensions to Windows Server to enables developers to create faster, more scalable, and more manageable applications.