> [!quote] [Martin Fowler](https://martinfowler.com/bliki/TwoHardThings.html) > There are only two hard things in Computer Science: cache invalidation and [[Naming Things]]. The *cache invalidation* is framed as *caching*, which has its own connotations (in terms of *semantics, access pattern, and performance*). However, the essence of this problem is dealing with the consequences of **denormalization**. If a single logical data has multiple representation, how do you ensure that they stay in sync? [Turning things off and on again](https://en.wikipedia.org/wiki/Power_cycling) is still the best thing to do when you encounter a bug. Many people are asked to "clear cache" before attempting to reproduce a bug. Joel in [[Joel on Software#10. Daily Builds]] asks you to do "clean builds". ![[Caching 1.svg]] # History [Cache invalidation really is one of the hardest things in computer science](https://surfingcomplexity.blog/2022/11/25/cache-invalidation-really-is-one-of-the-hardest-things-in-computer-science/) Historically, this refers to the problem of CPU register - memory caching. However, for the vast majority of programmers out there, we no longer think about this problem; we perceive it from the context of web services and caching expensive operations (ex: database). # Why is this a difficult problem? Every caching scheme makes assumptions: * About access patterns * Frequency of changes * About access path * How reads are performed * How writes are performed * Assumptions on cache staleness * how bad is it if the cache is stale? Examples: * Makefiles * timestamp-based caching. timestamp can be modified out-of-band; or files can be modified without modifying the timestamp. * Data Pipelines - batch versus incremental updates. "lambda architecture" * Terraform * [[Design Patterns#MVC]] * CI systems, Package Managers * Bazel, Nix, Docker... ## Why does it not matter (too) much #todo ## Special Case - [[Developer Environment]] #todo ## Special Case - Deployment [[2025-07-13]] In many ways, you can argue that "builds" are special cases of caching.