Redis Cache Course video #3 | Redis Cache implementation In.NET core 6.0 Web API | #rediscache



Redis Cache Course video #3 | Redis Cache implementation In.NET core 6.0 Web API | #rediscache

Redis Cache Course video #3 | Redis Cache implementation In.NET core 6.0 Web API | #rediscache

click the below link for installation of cache
https://youtu.be/__U-SDaQyxE

Follow the below steps for Redis Cache Implementation in .net core Web API

Step 1

Create the .NET Core API Web Application
Step 2
Install the following NuGet Packages which need step by step in our application

Microsoft.EntityFrameworkCore
Microsoft.EntityFrameworkCore.Design

Microsoft.EntityFrameworkCore.SqlServer

Microsoft.EntityFrameworkCore.Tools

Swashbuckle.AspNetCore
StackExchange.Redis

Step 3

Create the Model folder and create one Product Class inside that with details
Step 4
Create the DbContextClass Class for Database related operations
Step 5

we are going to create ICacheService Interface and CacheService Class for Redis Cache-related usage.

Step 6

Create the ProductController class

Step 7

Add the SQL Server connection string and Redis URL inside appsetting.json

Step 8

Register the ICacheService inside Configure Service method of Startup Class
Step 9

Create one ConfigurationManger Class to configure app 
Step 10

Create Connection Helper Class for Redis Connection

Step 11
run the application and add the data using swagger UI 

So here as you see, first, we check if the data is present inside the cache or not if data is available then return that. Next, if the value is not present in the Redis cache, then we apply the lock over there and then the request is locked and entered into the section and fetch the product details from the database, and then also set it to the cache and then return the data. So, what happened when the second user sends a request before the user one’s request is complete. So, in that case, the second request is in the queue and after completing the first user request the second request comes into the picture.

This is how we can implement redis cache for improving the performance of the application and avoid no of hits to the database.

Comments are closed.