On Memory

Not the human kind, the machine kind.

The file cabinet for computers is a database.

There are dozens of specialized databases.

Which you pick depends on the need.

Say you built an app for recipes.

You want to store all of your recipes in case you need them.

But you also want to make it easy for people to quickly get what they need.

As opposed to having to search through all of your recipes every time, you store copies of the most commonly searched for recipes in a separate file cabinet so you can find them faster.

That is the difference between the purpose of a database, permanent comprehensive memory, and a cache, temporary partial memory.

A database is stored on your computers disk, and a cache is stored on your computers RAM.

RAM is fast, but it’s smaller and more expensive than disk, and it forgets everything if the power goes out. That’s why you only keep your most commonly searched recipes there, not your whole collection.

It’s also why those copies often expire after a while (a TTL, or “time-to-live”), so if the original recipe gets edited, the fast copy doesn’t go stale and confuse people.

Here’s the part that makes RAM fast: every piece of data in RAM has an address, like a numbered mailbox. When you ask for something, RAM doesn’t search through everything to find it, it jumps straight to that exact address. Whereas for a disk that is a physical space on the disk that has to be navigated to by the head:

Leave a comment