Design the application architecture - Objective 1.5: Design a caching strategy Flashcards

1
Q

What is caching?

A

A strategy to improve performance by storing frequently used information in high-speed memory.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

How do you implement page output caching in ASP.Net MVC?

A

Add the OutputCache attribute to your action method.

Ex:

[OutputCache(Duration=120, VaryByParam="Name", Location="ServerAndClient")]
public ActionResult Index()
{
    return View("Index", myData);
}
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

Which property of the OutputCache attribute is used to configure the length of time to cache an action’s result?

A

Duration

Ex:

[OutputCache(Duration=120, VaryByParam="Name", Location="ServerAndClient")]
public ActionResult Index()
{
    return View("Index", myData);
}
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

How do you use the OutputCache attribute to disable caching?

A

Set Duration to zero.

Ex:

[OutputCache(Duration=0)]
public ActionResult Index()
{
    return View("Index", myData);
}
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

What are the valid values for the Location property of the OutputCache attribute?

A

Any, Client, Downstream, None, Server, ServerAndClient

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

What is the VaryByParam property of the OutputCache attribute used for?

A

Specifies the query string or form parameter names to store different versions of the cached output.

In the example code below, the output will be cached separately for each distinct value passed for Name in the query string of the request.

Ex:

[OutputCache(Duration=120, VaryByParam="Name", Location="ServerAndClient")]
public ActionResult Index()
{
    return View("Index", myData);
}
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

What is donut caching?

A

Allows caching of an entire page except for the dynamic parts of the page.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

How is donut caching achieved in ASP.Net MVC?

A

Partial views instead of the entire page are cached.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

What is the ChildActionOnly attribute used for?

A

Only allows the action to be called from Action or RenderAction HTML extension methods.

Ex:

[ChildActionOnly]
[OutputCache(Duration=60)]
public ActionResult ProductsChildAction()
{
    // Fetch products from the database and
    // pass it to the child view via its ViewBag
    ViewBag.Products = Model.GetProducts();
    return View();
}
How well did you know this?
1
Not at all
2
3
4
5
Perfectly