Skip to content

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

@antoine-lizee

Description

@antoine-lizee

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions