I think the word "cache" has so many different meanings in different contexts like below.
Note: In this list, the word "invalidated" means the source of cached value might be changed.
- Something like the cache in web browsers. The cache stores the result of each operation that had already called (Typically, these operations had cost large resources). The values in the cache might be invalidated partially because some input is volatile, but not coherent.
- Something like the result of precomputation. The cache stores the result of operations that programmers specified (because it will cost large time or memory). It might not be invalidated.
- Something like memoization. The cache stores the result of each operation that the programmers specified and had already called. It might not be invalidated but might be discarded because of time-space tradeoff (e.g. weak reference in Java). It should be coherent.
- Something like the in-memory views in RDBMS. The cache stores the values in files or tables that programmers specified, in order to reduce the cost of access or implement read-only view. It might be invalidated and must be coherent. It must be updated atomically.
- Something like on-memory copy of files. The cache stores the values in files or tables that programmers specified, in order to reduce the cost of access. Sometimes it might be invalidated, but the programmers can control the timing of invalidation. The coherency doesn't matter, but it must be updated atomically.
- Something like cache on CPUs or L2ARC. The cache stores the data that had already accessed, in order to reduce the cost of access. It might be updated or invalidated. It must be coherent, but doesn't have to be updated atomically.
- (Not in the table below) Something like on-memory data stores (e.g. memcached). The cache stores the values that programmers specified. It might be updated and never be invalidated (sometimes values are only in the cache!). It doesn't have to be updated atomically.
I tried to organize these concepts in a table like below:
Target of Cache | Invalidated? | Coherent? | Atomic? | Example | |
---|---|---|---|---|---|
1 | each | no | no | no | Memoization |
2 | each | no | no | yes | Memoization |
3 | each | no | yes | no | Memoization |
4 | each | no | yes | yes | Memoization |
5 | each | yes | no | no | Cache in Web Browsers |
6 | each | yes | no | yes | Cache in Web Browsers |
7 | each | yes | yes | no | ? |
8 | each | yes | yes | yes | ? |
9 | whole | no | no | no | Precomputation |
10 | whole | no | no | yes | Precomputation |
11 | whole | no | yes | no | Precomputation |
12 | whole | no | yes | yes | Precomputation |
13 | whole | yes | no | no | ? |
14 | whole | yes | no | yes | On-memory Copy of Files |
15 | whole | yes | yes | no | CPU Cache or L2ARC |
16 | whole | yes | yes | yes | In-memory Views in RDBMS |