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? :

Responses

1 Like

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

Related posts

Progressively enhancing maps

How I switched to high-resolution maps on The Session without degrading performance.

Secure tunes

Closing a security hole on The Session.

Going offline with microformats

The h-entry microformat and the Cache API are a perfect pairing for offline pages.

Am I cached or not?

Complementing my site’s service worker strategy with an extra interface element.

Move Fast and Don’t Break Things by Scott Jehl

A presentation at An Event Apart Seattle 2019.

Related links

Request with Intent: Caching Strategies in the Age of PWAs – A List Apart

Aaron outlines some sensible strategies for serving up images, including using the Cache API from your service worker script.

Tagged with

Offline Page Descriptions | Erik Runyon

Here’s a nice example of showing pages offline. It’s subtly different from what I’m doing on my own site, which goes to show that there’s no one-size-fits-all recipe when it comes to offline strategies.

Tagged with

Blog service workers and the chicken and the egg

This is a great little technique from Remy: when a service worker is being installed, you make sure that the page(s) the user is first visiting get added to a cache.

Tagged with

Distinguishing cached vs. network HTML requests in a Service Worker | Trys Mudford

Less than 24 hours after I put the call out for a solution to this gnarly service worker challenge, Trys has come up with a solution.

Tagged with

PushAPI without Notifications | Seblog

Remember when I wrote about using push without notifications? Sebastiaan has written up the details of the experiment he conducted at Indie Web Camp Berlin.

Tagged with

Previously on this day

5 years ago I wrote Third party

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

5 years ago I wrote CSS for all

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

13 years ago I wrote Pursuing semantic value

Agreeing and disagreeing with Divya.

15 years ago I wrote Collective action

Ajax feedback inspired by video games.

17 years ago I wrote Delusion

Agreement and disagreement.

23 years ago I wrote Procrastination

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