Solid Cache (Rails)
SSD instead of Redis โ database-based Rails cache store
GitHub: rails/solid_cache
Solid Cache is a DB-based cache store created by 37signals. It starts from a simple observation: "RAM is expensive, SSD is cheap." By using SSD (several TB) instead of Redis's memory limits (several GB), you can maintain a much larger cache at much lower cost.
Please refer to the Korean version for the detailed architecture analysis, including: the core idea of storing cache entries as DB table rows, the solid_cache_entries schema, cache read/write operations, the write-frequency-proportional probabilistic expiration mechanism (EXPIRY_MULTIPLIER = 2), Maglev consistent hashing for sharding, configuration options, and the Redis vs Solid Cache comparison.
Trade-off: Slightly slower (ms level), but can operate much larger caches at much lower cost. In most Rails apps, this difference is imperceptible.
Architecture Diagram
Cache Storage Structure
Cache Read/Write Flow
Expiry Mechanism (Probabilistic, not TTL)
Redis vs Solid Cache
Sharding (Maglev Consistent Hashing)
Key Points
Open rails/solid_cache repository on GitHub
app/models/solid_cache/entry.rb โ analyze cache entry model
app/models/solid_cache/entry/expiration.rb โ analyze expiration logic
lib/solid_cache/store.rb โ ActiveSupport::Cache::Store subclass structure
lib/solid_cache/store/expiry.rb โ write-based probabilistic expiration trigger
lib/solid_cache/maglev_hash.rb โ analyze consistent hashing implementation
lib/solid_cache/connections/ โ single DB vs sharding connection management
db/migrate/ โ check solid_cache_entries table schema
Pros
- ✓ No Redis needed โ simplified operations infrastructure
- ✓ SSD utilization โ much larger cache than RAM
- ✓ ActiveSupport compatible โ use Rails.cache API as-is
- ✓ Works by default in Rails 8 without separate configuration
- ✓ Maglev hashing โ elegant sharding support
- ✓ Encryption support โ leverages ActiveRecord Encryption
Cons
- ✗ Slower than Redis (RAM ~0.1ms vs SSD ~1-5ms)
- ✗ Increased DB load โ separate cache DB recommended
- ✗ Probabilistic expiration โ no exact expiry timing like TTL
- ✗ Redis still advantageous for high-performance real-time systems
- ✗ Always hits DB due to query cache being disabled