6. Caching for Faster Responses and Better Performance Flashcards

1
Q

What type of resilience strategy is caching?

A

It’s a proactive resilience strategy.

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

What does caching improve and how?

A

The performance of both the local and the remote services by reducing the load — the local service receives a response almost immediately and the remote service doesn’t even get hit with a request.

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

What are the two concerns to be mindful of when caching and why?

A

You need to be mindful of how long something can remain in the cache and the size of the items that you’re putting into the cache.

You worry about the lifetime of the item in the cache because you don’t want to return invalid or stale data, and you worry about the size of the items because you have limited resources.

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

What kind of policies can caching be used with, generic or non-generic ones?

A

It can be used with either.

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

How does a basic caching workflow look like?

A

When a request is made, the cache is checked to see if the value is already stored. If it is, that value is retrieved from the cache and returned as a response. If the value is not in the cache, we make the HTTP request, store the response in the cache, and then return the response. That value is now available for the next time the cache is hit.

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

What can be said about the context when it comes to caching and why?

A

The context must be passed when executing the request. The context execution key is used as a cache key and the cache key identifies the location in the cache to search for a value or to store a new value if that item is not present in the cache.

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

What can be said about the distributed cache?

A

Polly also supports the distributed cache. This allows us to share cached responses between multiple applications. Polly supports any implementation of the IDistributedCache including the Redis and SQL Server distributed caches.

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

What are Polly Cache delegates?

A

A number of functions that we can use when using Polly Cache, which helps diagnose the problems with the operation of our cache and/or performing logging related to the use of the cache.

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

What are the names of the Polly Cache delegates?

A
  1. OnCacheGet
  2. OnCacheMiss
  3. OnCachePut
  4. OnCacheError
  5. OnCacheGetError
  6. OnCachePutError
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

How do you define a Cache policy?

A

By using either the Cache or the CacheAsync method of the static Policy class and passing it a type, a cache provider object, and a TimeSpan object.

~~~
Policy.CacheAsync(
new MemoryCacheProvider(memoryCache),
TimeSpan.FromMinutes(5));
````

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

How can we define our own Cache policy when we want to do something with our cache that the default Cache policy doesn’t provide?

A

By using the IAsyncCacheProvider and the ICacheItemSerializer interfaces.

ps. Check Microsoft docs for more information.

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