2

I have two controllers like this

class New::StoresController < ApplicationController
  caches_action :index, cache_path: Proc.new {|c| c.params}, expires_in: cache_time(:long)
  caches_action :show, cache_path: Proc.new {|c| c.params}, expires_in: cache_time(:long)
  def index
  end
  def show
     # Here I use param[:store], params[:locale] and params[:ref]
  end
end

class New::StoreReviewsController < ApplicationController
  def create
     expire_action controller: '/new/stores', action: :show, \
                   store:params[:store], locale:"en", ref:"stores"
  end
end

I want to expire action New::StoresController#show on creation of a new StoreReview.

When the show action of Store is executed, the cache reads the following

Cache read: views/localhost:3000/en/stores/store-name

Read fragment views/localhost:3000/en/stores/store-name

While expire_action expires this fragment

Expire fragment views/localhost:3000/en/search?action=show&controller=new/stores&ref=stores Cache delete: views/localhost:3000/en/search?action=show&controller=new/stores

The question is should I use expire_fragment instead of expire_action as mentioned here ? rails 3 caching: expire action for named route

Also if I want to cache the action but not with all params what is the best way to do it?

Currently that's what I am doing

caches_action :show, cache_path: Proc.new {|c| c.params.select{ |p| [:controller,:action ,"locale", "store"].include? p} }, expires_in: cache_time(:long)
Community
  • 1
  • 1
Islam Azab
  • 700
  • 6
  • 22

1 Answers1

1

I've got the answer for that.

By default caches_action ignores parameters.

And for getting the right fragment to be expired I did the following

expire_action store_url(host: my_host, store: store_name, locale: locale])
Islam Azab
  • 700
  • 6
  • 22