Clean Architecture — ASP.NET Core API Starter Project using In-memory Cache Service

Discussing how caching can be implemented in an ASP.NET Core API solution based on Clean Architecture.

Shawn Shi
2 min readOct 3, 2020

UPDATE April 10, 2022: all projects in the GitHub repo have been upgraded to .NET 5.

This article extends the Clean Architecture — ASP.NET Core Partitioned Repository Pattern Using Azure Cosmos DB, where Clean Architecture, Database Partitioning, and Partitioned Repository Pattern are discussed.

Caching is a very important component in software system design, particularly for read-heavy services. Caching helps reduce repetitive read requests to the database when the same data is retrieved, and also improve the overall performance of the application.

In this article, I want to discuss how in-memory cache service can be used by a Web API project created using Clean Architecture. The example cache service will allow the user to set a list of todo items in cache, retrieve the list of todo items, and remove them from the cache. The high-level workflow for reading will become:

  • Do I have a list of todo items in cache? If so, retrieve them from cache and return..
  • If not, retrieve my list of todo items, set them in cache, and return.

Imagine you are constantly looking up your todo list, but are not actually completing any of them. Caching will help reduce read…

--

--

Shawn Shi

Senior Software Engineer at Microsoft. Ex-Machine Learning Engineer. When I am not building applications, I am playing with my kids or outside rock climbing!