vendredi 31 juillet 2015

How can I refresh the cache of model manually in rake file

How can I refresh the cache of model manually

I can cached pages with fragment,

and refresh it in outside rake task

But I have no idea how to refresh the cache inside the controller for fetching data from DB.

How could I refresh the cache in Rake file

def get_max_and_min_routes(airline_name, from, to)
  Rails.cache.fetch("I_AM_CACHE_KEY") do
    FETCH_FROM_DB
  end
end

rake file

action_controller = ActionController::Base.new
action_controller.expire_fragment("body_header")
action_controller.expire_fragment("index")
action_controller.expire_fragment("welcome_index_controller")
action_controller.expire_fragment("footer")

index.haml

- cache("index", skip_digest: true) do
  = render "historical_prices"
= render "common/recently_changed_prices"

Aucun commentaire:

Enregistrer un commentaire