Working with distributed caching
Most real-world enterprise apps fetch data from various data sources such as third-party DB, web services, and most importantly the web APIs are deployed either on cloud or server farm environment.
In the preceding cases, in-memory won't serve the purpose of caching as it's web server memory-based. To provide a more robust cache strategy across a deployed environment, it's recommended to use a distributed cache.
The distributed cache stores the data on a persistent store instead of web server memory, in this way cache data is available across the deployed environment.
The actual data store gets fewer requests than in-memory, therefore distributed cache survives the web server restarts, deployments, or even failure.
Distributed cache can either be implemented with Sql Server
or Redis
using the IDistributedCache
interface.
Using an SQL Server distributed cache
We will be using SQL Server for distributed cache; even Redis can also be used. To use SQL Server, use NuGet...