How does tiered caching work in the CF worker other than enabling it?

This is what I understand in terms of control

Workers have in-memory cache of x mb's, so you can define a memory cache via new Map for example.
Workers can use Cache API via caches.default.put

Both of these exist locally via colocation, so in-memory cache is going to be fastest, and then colo cache is second fastest in terms of latency for data retrieval.

If your data does not exist in both of those, tiered caching comes into play, and from my understanding its tied to the fetch api.

What does this mean exactly? Would love a code example of the breakdown for:

1. check in-memory cache (db response)
2. check local cache (db respoonse)
3. check tiered cache (db response)
4. if non of those have the data needed, it would fetch data from a database (origin)
Was this page helpful?