寻求可扩展、快速重启的非分布式缓存替代方案(支持磁盘持久化)
Great question! Since you’re hunting for a non-distributed cache that handles multi-GB datasets, supports fast restarts (with disk persistence to save/restore cache state on app shutdown/startup), and doesn’t require a paid license like Enterprise Ehcache/BigMemory Go, here are some strong open-source alternatives to check out:
Caffeine (with Custom Disk Persistence)
Caffeine is a high-performance Java caching library optimized for large in-memory caches. While it doesn’t include built-in disk persistence out of the box, you can easily add fast restart capabilities using itsCacheWriterandCacheLoaderinterfaces:- On app shutdown, use a
CacheWriterto serialize cache entries to a disk file (or pair it with a lightweight embedded store like RocksDB for better large-dataset performance). - On startup, use a
CacheLoaderto read and deserialize those entries back into the cache.
It’s lightweight, has excellent throughput, and handles multi-GB caches smoothly—perfect if you’re already in the Java ecosystem.
- On app shutdown, use a
MapDB
MapDB is an embedded key-value store built for Java, with seamless integration with Java Collections APIs (it acts just like aMapbut persists to disk). It checks all your boxes:- Uses memory-mapped files for fast access to large datasets (supports up to TBs, so multi-GB is trivial).
- Automatically persists cache state on app shutdown, and loads data back into memory (or keeps it in memory-mapped files for even faster startup) when you restart.
It’s a great drop-in replacement if you want something that feels like a standard Java cache but with built-in fast restart capabilities.
RocksDB
Developed by Facebook, RocksDB is a high-performance embedded key-value store optimized for fast storage and retrieval. While it’s not a traditional cache library, it works exceptionally well as a local persistent cache:- Stores data on disk by default, but uses an in-memory block cache for hot data, balancing speed and persistence.
- Restarts are fast because it loads only necessary metadata and lazy-loads data as needed—ideal for multi-GB datasets where you don’t want to wait for the entire cache to load into memory upfront.
It’s a bit lower-level than Caffeine or MapDB, but offers unmatched performance for large-scale local storage.
Redis (Standalone Mode)
While Redis is often used for distributed caching, its standalone (single-instance) mode works perfectly as a local persistent cache. It supports:- RDB snapshots: Periodically saves the entire cache to disk, which loads quickly on restart. For multi-GB caches, RDB loads are far faster than AOF logs.
- In-memory-first operation with disk persistence as a backup—so your cache stays fast during runtime, and you don’t lose data on restart.
If you’re already familiar with Redis’s API and tooling, this is a low-friction option that scales well for multi-GB workloads.
Quick Notes to Consider
- If you’re working in a Java project, Caffeine + custom persistence or MapDB will integrate most naturally with your existing code.
- For maximum performance with very large datasets, RocksDB is the way to go.
- If you want a familiar API and ecosystem, standalone Redis is a solid choice.
内容的提问来源于stack exchange,提问作者user2698580

