Skip to content
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

Rails.cache.fetch is active in spite of ActionController::Base.perform_caching #20733

Closed
antoine-lizee opened this issue Jun 29, 2015 · 6 comments
Labels

Comments

@antoine-lizee
Copy link
Contributor

I am not sure how to create a simple Minimal Working Example.
This happens when testing my caching behavior, and something along these lines fails:

  context "without cache" do

    it "should return the appropriate result, computing it every time", :caching => false do
      p ActionController::Base.perform_caching
      Object.should_receive(:where).exactly(4).and_call_original
      result1 = SomeService.action(args1, args2)
      result2 = SomeService.action(args1, args2)
    end

  end

...even though false is printed out for the ActionController::Base.perform_caching.
[I set this to false by the :caching => false option of the bloc (I use a hook)]

If I annihilate caching by switching from the default :memory_store to the :null_store for the testing environment, the test passes as expected.
[I just add config.cache_store = :null_store in test.rb]

My action method uses the core caching from Rails:

def action(args1, args2):
...
  objects = Rails.cache.fetch(cache_key, expires_in: 5.days) do
    object.where(id: args1).where(charac: args2).includes(...).to_a
  end
...
end
@matthewd
Copy link
Member

This sounds like expected behaviour to me; maybe the documentation can be improved.

It says ActionController::Base.perform_caching can be used "to turn off all caching". It could be clearer, but it means "to turn off all caching involving this module" -- direct access to Rails.cache is entirely outside ActionController's responsibility.

If you want to prevent all caching, rather than just having AC opt out of using it, :null_store what you want.

@antoine-lizee
Copy link
Contributor Author

Well, after looking at the code from the active_support library, I am wondering if low-level caching has ever been meant to answer from ActionController::Base.perform_caching... Maybe we should improve the documentation that is clearly misleading here: http://guides.rubyonrails.org/caching_with_rails.html

@antoine-lizee
Copy link
Contributor Author

@matthewd Yeah, got it. But the caching guide of rails is clearly misleading - it talks about the perform_caching as if it governed the while thing, including the low level caching stuff it is describing later on. I'll propose a PR.

@antoine-lizee
Copy link
Contributor Author

On a related note, what would involve supporting this?

@rails-bot
Copy link

This issue has been automatically marked as stale because it has not been commented on for at least
three months.

The resources of the Rails team are limited, and so we are asking for your help.

If you can still reproduce this error on the 4-2-stable, 4-1-stable branches or on master,
please reply with all of the information you have about it in order to keep the issue open.

Thank you for all your contributions.

@antoine-lizee
Copy link
Contributor Author

Closing, as the doc PR has been merged. Discussion could be restarted elsewhere if some new feature is desirable around this issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants
@matthewd @antoine-lizee @rails-bot and others