Welcome to the Rails "Solid" Era
If you’re new to Rails or you’ve recently heard about Rails 8, you’ve probably come across these three mysterious names: Solid Cache, Solid Cable and Solid Queue. These three gems form what we call the "Solid Triumvirate" (or "Solid Trifecta" in English) and represent one of Rails' most significant evolutions in years.
But why all the excitement? Because these three tools allow you to build a Rails application complete and performant without Redis or any external dependency. No more headaches configuring multiple services! Everything runs with your database.
In this series of articles, we will explore in depth each component of the triumvirate, understand how they work, and most importantly, learn to use them with concrete examples. Whether you’re a junior developer or simply curious, by the end of this read you’ll master these three essential Rails 8 tools.
We will also talk a lot about Redis, so if you want to learn what it is or refresh your memory, read my ultra-complete article on the subject: Redis and Rails 8 : The Complete Guide for Junior Developers
Why does the Solid Triumvirate exist?
The traditional problem
Before Rails 8, if you wanted to build a modern Rails application with advanced features, your stack generally looked like this:
- PostgreSQL or MySQL : your primary database
- Redis : for the cache
- Redis or Sidekiq : for background jobs
- Redis : for Action Cable (real-time features)
Do you see the pattern? Redis everywhere! And while Redis is excellent, it introduces several constraints:
- Deployment complexity : one more service to manage, monitor, and maintain
- Additional costs : on platforms like Heroku, every add-on has a price
- External dependency : if Redis goes down, several parts of your app go down too
- Learning curve : another technology to learn for juniors
The "Solid" philosophy
The Basecamp team (the creators of Rails) had a simple but powerful reflection:
"What if we used our database for everything?"
With modern SSDs (notably NVMe), disk storage has become fast enough to rival RAM in many use cases. Moreover, modern databases like PostgreSQL and MySQL have made huge performance gains.
The result? A Rails that’s simpler, lighter, and just as performant for 80% of applications.
Solid Cache: The Database-Based Cache
What is cache, exactly?
Before diving into Solid Cache, let’s understand what cache is. Imagine you have an e-commerce site with a homepage that shows the most popular products. On each visit, the server must:
- Query the database
- Calculate the statistics
- Generate the HTML
- Send the response
If you have 1,000 visitors per minute, you repeat this operation 1,000 times... to display exactly the same content! It’s a waste of resources.
The cache solves this problem by storing the result of this costly operation in memory. Next time, instead of recomputing everything, you simply retrieve the stored result. It’s like keeping your favorite coffee mug on your desk rather than in the kitchen cabinet.
Solid Cache: How does it work?
Solid Cache replaces traditional solutions (Redis, Memcached) with a database-based caching system based on your database.
The architecture
Solid Cache uses a simple table in your database called solid_cache_entries. Here’s its structure :
The principle :
- When you cache data, it is stored in this table
- When you retrieve it, Rails runs a ultra-fast SQL query on the index key_hash
- Entries are automatically cleaned according to your configuration
Why is it fast even with disk storage?
You might be wondering: "A disk-based database can’t be as fast as Redis in RAM, right?"
Excellent question! Here’s why it works:
- Modern SSDs are ultra-fast : NVMe reach impressive read/write speeds
- Database-level caching : PostgreSQL and MySQL cache frequently accessed data in RAM
- Massive storage : With disk, you can store 100x more data than Redis, meaning fewer cache misses
- Longer retention : Basecamp keeps 10 TB of cache for 60 days!
Installation and Configuration
On Rails 8
Good news: Solid Cache is enabled by default on Rails 8! Nothing to do when creating a new app:
That’s it! Solid Cache is already configured in production.
On Rails 7.1+ (manual installation)
If you’re using an older version of Rails 8:
Then configure your config/database.yml:
And in config/environments/production.rb :
Configuration in config/cache.yml
Practical Examples
Example 1: Cache a costly query
How it works:
- The first time, Rails finds nothing in the cache
- The block executes, the query is performed
- The result is stored in solid_cache_entries with the key "popular_products"
- Subsequent visits retrieve the cache result directly
- After 1 hour, the entry expires and the cycle restarts
Example 2: Cache a complex calculation
Example 3: Cache a partial view
In your views, you can use fragment caching:
Rails automatically generates a unique key based on:
The model (Product)
- The product’s ID
- The last update (updated_at)
- If the product changes, the cache is automatically invalidated!
Example 4: Manage the cache manually
Maintenance Operations
Enable caching in development
By default, caching is disabled in development. To enable it:
This command creates a file tmp/caching-dev.txt. Restart it to disable caching.
Monitoring the cache
Solid Cache vs Redis: When to use which?
|
Criterion
|
Solid Cache
|
Redis
|
|---|---|---|
|
Speed
|
Fast (disk + DB cache)
|
Very fast (pure RAM)
|
|
Capacity
|
Massive (several TBs)
|
Limited (RAM is expensive)
|
|
Persistence
|
Yes, stored on disk
|
Optional
|
|
Simplicity
|
Very simple (built into Rails)
|
Requires external configuration
|
|
Cost
|
Low (uses disk storage)
|
Higher (RAM-based)
|
|
Use Cases
|
Small to medium apps
|
High-performance apps
|
Use Solid Cache if:
- You’re starting a new Rails 8 project
- You want to simplify your infrastructure
- You don’t need extreme performance
- You want to store a lot of data in cache
Keep Redis if:
- You need maximum performance
- You use Redis advanced features (pub/sub, sorted sets). Not sure what that is? Go read my article on the subject: Redis and Rails 8: The Complete Guide for Junior Developers
- You already have a well-tuned Redis infrastructure
Conclusion: Solid Cache, the native Rails super cache
Solid Cache is Rails’ cache reimagined for simplicity and performance. By leveraging Active Record and a SQL base, it eliminates the friction associated with Redis while offering a familiar and powerful API. Whether it’s to optimize the performance of your views, reduce calls to external services, or accelerate your queries, Solid Cache integrates naturally into your Rails stack.
With Rails 8 officially adopting it, it’s time to say goodbye to complex configurations and enjoy a robust, readable, and easy-to-maintain cache.
🚀 Fewer dependencies, more clarity. Solid Cache is Rails’ cache like we’ve always dreamed of.
