New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Cache_store not set when using ActionCtrl::API and manually including Caching #35602
Comments
Currently ActionController::API doesn't include Caching module, so it can't perform caching. And even if users include it later manually, it won't inherit application's default cache store for action_controllers. So the only way to solve this issue is to include Caching module in ActionController::API, too. This closes rails#35602
@dennym FYI, I already opened a PR for that. I hope them would accept it and backport it to 5.2 😄 |
Rails doesn't support view caching in api controllers by default but the document didn't clearerly declare this nor the manual config needed after including the module manually. So we'll see people get confused like rails#35602.
Mhm interesting... thanks for the input and work :) So the cache_store in the controller is just responsible for view caching? I was under the impression that it does couple of magical caching in the background. If its its just for view caching I personally actually don't need it. But when setting a new rails project up with |
That is a good point. We need to double check if that config affects other things but I believe we can remove from the api apps. |
As suggested in rails#35602 (comment), because we don't provide view caching and doesn't include `ActionController::Caching` for api apps, we should also avoid generating ```ruby config.action_controller.perform_caching = true ``` for those api apps. So it won't confuse people. **But because `perform_caching` will be `true` if not set, the behavior of the app would still be the same without these configs.**
Steps to reproduce
Simple setup some cache_store for the Application
Actual behavior
Since I have
config.action_controller.perform_caching = true
I was checking if my dalli store was available since I useActionController::API
. After digging through the repository I found out I had to include manuallyActionController::Caching
. Ezpz but after checking for cache_store it turns out that the cache store is nil and therefor not set.To eliminate any other configuration errors I just checked against having the
ApplicationController
inherit fromActionController::Base
and there it returns the expected cache store.Expected behavior
Well both setups should give the same output. Its also mentioned here that the modules can be included.
As a side thought:
When you
rails new foo --api
then it setsApplicationController
toActionController::API
instead ofBase
and also sets production toconfig.action_controller.perform_caching = true
Which wouldn't work then at all.System configuration
Rails version: 5.2.2
Ruby version: 2.6.1
The text was updated successfully, but these errors were encountered: