Forgotten :cache_store in Rails documentation
The main objective of my article is to share my thought process and demonstrate how I handled the issues that I encountered. Also, It has a message like "do not trust the documentation 100%, sometimes you need to check the source code, because what was forgotten in the documentation cannot be forgotten there"
Once, when I was configuring Rails sessions, I discovered that Rails was storing encrypted session information on the client-side. I wanted to change this so that the client would only store the session ID, and the server would store the session information associated with that ID. However, when I looked at the documentation, I found that there were only four options for session storage: :cookie_store, :mem_cache_store, a custom store, or :disabled. Unfortunately, there was no option for a cache store.
Then I started investigating where I could find a method to store the session in the cache (I decided that this would be the best solution for my issue).
To start my investigation, I looked at the session store sources:
What I found was:
- If the session store is not defined, we write the first argument to @session_store. If we pass :active_record_store, we also check if the appropriate gem is included in our project's Gemfile.
- If the session store is defined, we return a specific class depending on the argument that we pass.
The next step was to look at where the session_store method is called:
- This code shows how Rails sets the default value of :cookie_store for the session store.
- This code shows how we set the session store to the Rails middleware.
Next, I revisited the session_store source to look at the 'else' section and find the arguments that are defined in the Rails documentation:
- :disabled - 👍
- :active_record_store - 👍
- A symbol? But we expected to see at least :cookie_store and :mem_cache_store - 👎
Next, I looked at what ActionDispatch::Session has for us:
And there they are! We found what we were looking for.
- :cookie_store - 👍
- :mem_cache_store - 👍
- :cache_store - 🤔
However, there is no :cache_store argument in documentation! Okay, lets got to feedback section
Yep, we have found some 🙃
Let's go to contribute to Rails documentation
Wait, what? O.o
It actually contains :cache_store now! Someone must have fixed it, but who and when did it happen?
I downloaded the Rails repository and used Git to check who made these changes
- I belive it was fixed on March 28th, 2022 by Ghouse Mohamed.
- It definitely seems like it was fixed now 🙃
Why didn't the official Rails documentation include this? It's because the top image shows the main branch, while the documentation is related to the '22.214.171.124' tag which corresponds to the 7-0-stable branch. This branch is missing the commit from the main branch that resolved the issue. My assumption is that the fix from the main branch will be incorporated into the next major release of Rails.
Clap to support the author, help others find it, and make your opinion count.