Designing a cache abstraction layer using distributed caching
In enterprise applications, it's always good to have a wrapper class on top of an underlying cache implementation as it abstracts the core logic of caching and can also be used as one single class that holds application-wide default cache entry options.
We will be implementing a cache wrapper class with an underlying store as Azure Cache for Redis using the IDistributedCache
implementation. It's a .NET Standard 2.1 class library; the source code for this library is available in the Packt.Ecommerce.Caching
project. Any class that wants to cache data should inject IDistributedCacheService
using constructor injection and can call the following various methods:
AddOrUpdateCacheAsync<T>
: Adds or updates cache entries of typeT
asynchronouslyAddOrUpdateCacheStringAsync
: Adds or updates cache entries of the string type asynchronouslyGetCacheAsync<T>
: Gets cache entries of typeT
asynchronously...