Should I Add Caching to my Web Application?

Date Published: 27 April 2018

Should I Add Caching to my Web Application?

I created a helpful flow chart to use when answering the question, Should I add caching to my web application (or, "Should I implement caching in my ASP.NET (Core) App")?

Most web applications have at least some data that's used frequently by the site, but doesn't change frequently. There's no reason not to cache this data in most cases. If you use a pattern like the CachedRepository, it's straightforward to add caching on an as-needed basis while following SOLID principles and keeping good separation of concerns.

 

By the way, this flow chart was generated by WebGraphViz using this markup:

digraph finite_state_machine { size="8,5" node [shape = rectangle, color=blue]; "Should I implement caching in my ASP.NET App?"; node [shape = rectangle, color=red]; "You probably don't need a cache."; node [shape = rectangle, color=green]; "You should implement caching."; node [shape = diamond, color=black] "Should I implement caching in my ASP.NET App?" -> "Do you read data from an external source?"; "Do you read data from an external source?" -> "You probably don't need a cache." [ label = "NO" ]; "Do you read data from an external source?" -> "Is some of that data readonly/readmostly?"[ label = "YES" ]; "Is some of that data readonly/readmostly?" -> "Is web site performance important?" [ label = "YES" ]; "Is some of that data readonly/readmostly?" -> "You probably don't need a cache." [ label = "NO" ]; "Is web site performance important?" -> "Is reducing database load important?" [ label = "YES" ]; "Is web site performance important?" -> "You probably don't need a cache." [ label = "NO" ]; "Is reducing database load important?" -> "You probably don't need a cache." [ label = "NO" ]; "Is reducing database load important?" -> "You should implement caching." [ label = "YES" ]; }

Steve Smith

About Ardalis

Software Architect

Steve is an experienced software architect and trainer, focusing on code quality and Domain-Driven Design with .NET.