FSCache - I created a new lightweight software for file caching on our home servers

Posted by Meisgoot312@reddit | linux | View on Reddit | 28 comments

Hey everyone!

tl;dr fscache - Lightweight Linux FUSE caching software that caches any existing FS.

You might have seen me from my Plex post here. Since then, a few people have reached out to me to ask if I could make this library generic. After spending a few days working on refactoring the codebase and testing non-stop, I've finally gotten to a point I can present it as a new binary FSCache. One of the core principles I had when developing this was that "it just works" with minimum effort. Would love to get some feedback and bug reports. My dream is to eventually see this on any ole apt command. Now that it's generic, it makes sense to post in r/Linux.

In my homelab journey, I wanted to have a simple file caching software that 1) Mounted on an existing filesystem, 2) Was filesystem agnostic, and 3) Had some rules I could tune. Unfortunately, existing solutions had too much "churn" for me to truly do what I want. B-Cache only works on new filesystems, MergerFS requires tiering and custom scripts, LVMCache is not really compatible with SnapRaid, etc. There was no perfect solution.

That's why I created FSCache. 3 lines of config edits and execute. The benefit of FSCache is that it works using FUSE overmounting, it sits on top of ANY number of existing filesystems and allows you to cache files to another drive (SSD cache) based on a set of rules. At the moment it has two modes, prefetch mode, which is basically just a generic cacher and plex-episode-prediction mode (which handles Plex specific setups). When a file is moved into Cache, the cached file it delivered to the requestor instead of the backing file. The requesting software has zero awareness of what's happening.

There are run commands for FSCache. There is fscache start --config and there is fscache watch. Start simply starts the caching daemon, this can be setup as a service. fscache watch opens up a gui and attaches to the daemon - this of it as top or nvidia-smi if you've used that before.

The generic cacher works with any rule you setup, Ex. If you have a game drive that people access quite often, you can set it up to cache the hit file + neighboring files, you can set it up to cache hits only, and you can even ask it to cache the entire parent folder + all subdirs.

The Plex Cacher intercepts I/O and has special integrations that cache plex specific file I/O. The specific logic is to ignore scans and only focus on real sessions. There may be some misses, but would love to see bug reports for these. It's very hard to chase these issues down.

This tool is still in development, so please report any bugs you might see. I have done testing myself and have extensive system level tests in the codebase, but the amount of testing can do alone is only so much.

Big thanks to u/trapexit, author of MergerFS. He gave me some comments about my original code and inspired me to use FUSE via MergerFS. I look forward to more conversations!

As always, be careful. This tool was build to be non-destructive, heavily tested (incl. E2E tests), and read-only (outside of cache), but as with all FS Operations, please be careful of software in development.

https://github.com/DudeCmonMan/fscache

A bit of background on myself

I'm a homelab enthusiast, I am lucky enough to enjoy the monotony of working on a server that provides to people. I'm a Software Engineer with a background in hardware and embedded systems, so this kind of stuff is fun for me. The work I do for my career and my hobbies are directly aligned, I am blessed that I find comfort in messing with servers.

I generally write in Python, but I've recently moved to Rust and will probably be using Rust completely going forward. It's good to back to compiled binaries. I've come full circle from C++ as my "native language" to C#, to Python, even VBA, now back to a compiled language Rust. Being language agnostic is great, especially in the age of AI.

I've worked on a ton of codebases, but this is my first opensource one that I want to share with the world.

For the more technical

FSCache uses these main layers:
FUSE -> Action Engine (event emitter) -> Preset Integration + SQLite Cache Database