lulalala
lulalala

Reputation: 17981

How to set perform_caching dynamically in Rails

I want to control whether to perform caching at runtime.

I wrote an admin action like the following to test the idea (trying to set it to true):

  def togglecache
    Rails.configuration.action_controller.perform_caching = true
    render :index
  end

However after setting it, caching is still not taking effect.

How to achieve this, if it is possible at all?

Upvotes: 3

Views: 446

Answers (1)

Alexander Revutsky
Alexander Revutsky

Reputation: 1333

  ActionController::Base.perform_caching = true
  Rails.cache.clear
  load 'app/controllers/name_controller.rb'

Upvotes: 1

Related Questions