On-Disk Caching with SQLite
2 Jul 2020Recently, a project I was working on required a cache that would ideally be
capable of storing tens of millions of entries, reaching into the
multiple-terabyte range. At this scale, using a single spinning disk is
significantly cheaper than storing everything in memory, which Redis or
Memcached would require. Another classic KV store, LevelDB, also ends up being
impractical because it writes the value for each key to disk multiple times. If
your values are small, LevelDB can be really really performant, but in my case
the values are moderately sized (tens of kilobytes) and writing them to disk
multiple times quickly becomes user-visible. And finally, I expected that
storing this many entries on-disk as individual files in a folder would cause
issues with inode exhaustion, and ultimately, the ACID guarantees that a
filesystem provides have never been super clear to me.
Keep reading »