What is LazyCache and when should I use it?
masterLazyCache is a simple, thread-safe, in-memory caching service. It is designed to wrap Microsoft.Extensions.Caching and Lazy<T> to provide a developer-friendly, generics-based API.
Use cases:
- Caching database calls.
- Caching complex object graph building routines.
- Caching web service calls.
Key characteristics:
- Guaranteed single evaluation: The factory delegate is guaranteed to run only once.
- Strongly typed: Uses generics so you don't need to cast objects when retrieving them.
- Exception safety: It prevents inadvertently caching an exception by removing
Lazyobjects that evaluate to an exception. - Async support: Provides
GetOrAddAsync()for single evaluation of async delegates.