A Head Start: Caching and Prefetching

photo-1453946610176-6be21147c400.jpeg

At Dwell we’re working to ensure that you can access the Bible as quickly as possible. We’ve already talked about about why that’s difficult, and we’ve covered a few of the ways we’re tackling the problem. Today, I’d like to talk about two more tools in our arsenal that I’ve been working on lately: Caching, and Prefetching.

Caching

In the context of computing, caching is the process of locally storing data that is hard to get, so that the next time you need it, it’s close by. It’s sort of like carrying a pen in your pocket or purse while you’re at home. Sure, you could go all the way to the junk drawer in the kitchen every time you need to write something down, but it’s a lot easier if you already have one with you.

At the same time, you probably don’t also keep a sharpie, dry erase marker, and colored pencils in your pocket, because you’re much less likely to need those on a regular basis. In the same way, we only cache some data, because we don’t have room to cache all data.

One key piece of data that we cache in the app is the album artwork for each track. When you first load a track, we have to go out to the internet and download that album artwork, because we wouldn’t have room to store all of them on your phone (and, we’re making new ones all the time).

Once we’ve downloaded that album artwork, however, we can keep it around so that the next time we need to show it to you, we don’t have to go out to the internet to download it, we can just grab the locally stored copy, which loads hundreds or thousands of times more quickly than downloading a copy again. And if a cached file starts to get stale (because it’s old and unused) we can just delete that local copy to free up some space.

We also apply caching to our audio files, both scripture readings and music tracks. By keeping things close by, we can take advantage of the speed boost whenever we need to play a track again.

This all works great for content that you’ve already asked for, like album artwork or tracks that you’ve played. But what if we could get tracks that you’ll want in the future, even before you need them? This is where prefetching comes in.

Prefetching

Prefetching is just like caching, but we’re attempting to get data that you’ll need in the future, not just keeping data around once you’ve used it. A great example of this is Listening Plan tracks.

When you first start a Listening Plan we won’t have any of the tracks stored on your phone, so we’ll have to go get the first one and download (or stream) it. But, if you listen to track 1 of a plan, there’s a pretty good chance you’ll listen to track 2. So, we’ll go ahead and download track 2 in the background for you. That way, when you go to play track 2 the next morning, it will already be downloaded, waiting to play. It can start instantly, and won’t be subject to your cell phone connection dropping out while you pull out of your driveway.

Is this Offline Mode?

Not quite. While Prefetching and Caching are two important pieces, they don’t comprise a true offline mode. For that, we’ll need to have even more data available on the phone, and even more tools built to allow you to decide what gets stored, and for how long. Caching, for example, doesn’t guarantee that any file will stay on the phone; we purge those as necessary to save space on your device. In an offline mode, you’ll want unplayed files to stay until you’ve been able to listen, and you’d be pretty disappointed if your files disappeared before you could play them.

Still, Prefetching and Caching are important milestones on our way to a true offline mode (which we’re committed to building, though we won’t have it ready until well after launch). And, in the mean time, they help all our listeners spend less time waiting to download and more time with the most important book of all: the Bible.

Jeff McFadden