This project uses ASP.NET Core's IDistributedCache abstraction with Redis to share cached data between application instances. If you only need a cache inside one application process, my in-memory caching project is a better starting point.
I've also blogged this with a full explanation of how this is achieved.
main targets .NET 10 LTS. The unsupported .NET 5 version remains available on the dotnet5 branch for historical reference.
- User requests a user object.
- App server checks if we already have a user in the cache and return the object if present.
- App server makes a HTTP call to retrieve the list of users.
- Users service returns the users list to the app server.
- App server sends the users list to the distributed (Redis) cache.
- App server gets the cached version until it expires (TTL).
- User gets the cached user object.
Requirements:
- .NET 10 SDK
- Docker with Docker Compose
Start Redis:
docker compose up -dRun the application:
dotnet run --project DistributedCache/DistributedCache.csprojBuild and test the solution:
dotnet testHaving any issues or troubles getting started? Get in touch with me
Has this Project helped you learn something new? or helped you at work? Please consider giving a ⭐️ if this project helped you!
Please share this Repository within your developer community, if you think that this would make a difference! Cheers.
PRs are welcome! Thank you
