Caching and storing

When I was speaking at conferences last year about service workers, I’d introduce the Cache API. I wanted some way of explaining the difference between caching and other kinds of storage.

The way I explained was that, while you might store stuff for a long time, you’d only cache stuff that you knew you were going to need again. So according to that definition, when you make a backup of your hard drive, that’s not caching …becuase you hope you’ll never need to use the backup.

But that explanation never sat well with me. Then more recently, I was chatting with Amber about caching. Once again, we trying to define the difference between, say, the Cache API and things like LocalStorage and IndexedDB. At some point, we realised the fundamental difference: caches are for copies.

Think about it. If you store something in LocalStorage or IndexedDB, that’s the canonical home for that data. But anything you put into a cache must be a copy of something that exists elsewhere. That’s true of the Cache API, the browser cache, and caches on the server. An item in one of those caches is never the original—it’s always a copy of something that has a canonical home elsewhere.

By that definition, backing up your hard drive definitely is caching.

Anyway, I was glad to finally have a working definition to differentiate between caching and storing.

Have you published a response to this? :


1 Like

# Liked by Dan Johnson on Thursday, November 12th, 2020 at 11:27pm

Previously on this day

1 year ago I wrote Third party

Imagine a web where cookies and JavaScript had to be self-hosted.

1 year ago I wrote CSS for all

Whatever happened to Mozilla’s stated policy of restricting new CSS properties to HTTPS?

9 years ago I wrote Pursuing semantic value

Agreeing and disagreeing with Divya.

11 years ago I wrote Collective action

Ajax feedback inspired by video games.

13 years ago I wrote Delusion

Agreement and disagreement.

19 years ago I wrote Procrastination

I spent most of today making tweaks and changes to my little portal.