Learn how Rails 8’s Solid Cache enhances database-backed caching with built-in encryption, sharding, and GDPR-compliant data retention policies. Discover how it offers secure, persistent storage, making it a powerful alternative to Redis for privacy-sensitive applications.
Next up, let’s take a look at Solid Cache, the sibling to Solid Queue and one of the three Solid gems that are now default in Rails 8.
What is Solid Cache?
As you might expect, Solid Cache powers the caching system in Rails applications.
Looking at the schema file, we see that Solid Cache has a much simpler structure compared to Solid Queue—it consists of just one table where all cache entries are stored. While the architectural decisions behind Solid Cache have been discussed in conference talks, for now, let’s focus on how it’s configured and used.
Configuring Solid Cache in Rails 8
Opening config/cache.yml, we see the default cache settings:
- Max Cache Size → 256MB.
- Namespace Mapping → Matches the current environment (development, production, test, etc.).
- Database Storage → In production, Solid Cache uses a dedicated database file.
This brings us back to database.yml, where Rails automatically separates each component into its own SQLite database:
- Primary Database → Stores application models.
- Queue Database → Handles background jobs.
- Cache Database → Manages cached data.
- ActionCable Database → Handles WebSocket messages.
This separation improves performance and concurrency, ensuring cache operations don’t interfere with database writes or job processing.
How Solid Cache Works in Development vs. Production
There is a key difference in how caching works between development and production:
- Production → Uses the Solid Cache database adapter for persistent caching.
- Development → Uses in-memory caching by default (no persistence).
This means that in development:
- Jobs and cache entries exist only in memory.
- They disappear when the process stops.
- It’s fast and requires no setup.
However, if you want to use Solid Cache in development, you can manually enable it by following setup scripts.
Key Features of Solid Cache
Solid Cache provides several powerful features that make it a robust alternative to Redis or Memcached:
- Encrypted Cache Entries → Rails’ built-in encryption support ensures cache data is encrypted at rest and in transit. This is critical for privacy-sensitive applications like email services or social platforms.
- Database Sharding → Allows cache data to be distributed across multiple databases for scalability. While we’ll start with a single cache database, this feature makes horizontal scaling easy. 37signals uses this approach to shard cache across multiple large databases in Basecamp.
- Data Retention Policies → You can set a Max Age for cached data. This helps meet compliance regulations like GDPR, ensuring sensitive data is purged after a set period (e.g., 60 days).
Why Solid Cache is an Exciting Default for Rails 8
I’m excited that Solid Cache is now a Rails default because it:
- Removes the need for third-party caching solutions (like Redis).
- Works seamlessly with Rails’ encryption and sharding features.
- Provides a production-ready caching system with zero extra setup.
With Solid Queue handling background jobs and Solid Cache managing fast, secure storage, Rails 8 is making it easier than ever to build scalable, production-grade applications.
In the next video, we’ll look at Solid Cable, which powers WebSocket messaging.