Forum: Ruby on Rails Action caching with dynamic cache names

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
8bb6af7547c07a6d41e5f82515f59a83?d=identicon&s=25 Lundie (Guest)
on 2008-12-04 16:14
(Received via mailing list)
Hi,

I am attempting to cache a page that varies depending on the URL that
you go to.  For example, http://mydomain.com/member_name goes to the
same action and controller as http://mydomain.com/other_member, but
the page is customized to the member.

I am currently accomplishing this with the following:

applications_controller.rb

caches_action :new, :cache_path => :new_cache_path.to_proc
....
private
  def new_cache_path
      params[:member_name]
  end

This works fine, but I run into issues when I try and sweep the cache
because im am not sure how I can pass the member_name parameter to the
sweeper.  The following is what I am using for a sweeper:

members_controller.rb

cache_sweeper :member_sweeper, :only => [ :update ]


class MemberSweeper < ActionController::Caching::Sweeper
  observe Member

  def after_save(product)
    expire_cache(product)
  end

  def after_destroy(product)
    expire_cache(product)
  end

  def expire_cache(product)
    expire_action 'member_name'
  end
end


The members name is being passed to the member controller via the
submitted form, I just need to know if it is possible to pass it to
the sweeper.

Thanks for your help!

Ryan
This topic is locked and can not be replied to.