Skip to content

aimenux/DistributedCacheDemo

Repository files navigation

.NET

DistributedCacheDemo

Using distributed cache in web api applications

In this repo, i m using a distributed cache to improve web api responsiveness.

The sample provided in this repo is based on :

  • a distributed cache to save/load cached websites

  • a service to compute content length for a white listed website

  • an exception filter to handle some exceptions as bad requests

  • a validation attribute to validate route parameters

The distributed cache can be configured (via appsettings.json file) to use :

For redis cache, you can use docker to run redis server.

docker run -d --name local-redis -p 6379:6379 redis/redis-stack-server:latest

For sql server cache, you can use docker to run sql server.

docker run -e "ACCEPT_EULA=Y" -e "MSSQL_SA_PASSWORD=@Pa5sw0rd!" -p 1433:1433 --name local-sqlserver -d mcr.microsoft.com/mssql/server:2022-latest

Use the sql script CreateDatabase.sql in order to create the database CacheDatabase.

Use the global tool dotnet-sql-cache in order to create the table CacheTable.

dotnet sql-cache create "Server=localhost,1433;Database=CacheDatabase;User Id=sa;Password=@Pa5sw0rd!;TrustServerCertificate=True;" dbo CacheTable

Tools : net 9.0, distributed cache, serilog

About

Using distributed cache in web api applications

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published