# Action caching with dynamic cache names

**URL:** <https://www.ruby-forum.com/t/action-caching-with-dynamic-cache-names/154857>\
**Category:** Rails\
**Created:** [December 4, 2008, 4:14pm UTC](https://www.ruby-forum.com/t/action-caching-with-dynamic-cache-names/154857 "2008-12-04T16:14:44Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![casper\_the\_ghost](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/58956e/32.png) [@casper\_the\_ghost](https://www.ruby-forum.com/u/casper_the_ghost)\
**Post date:** [December 4, 2008, 4:14pm UTC](https://www.ruby-forum.com/t/action-caching-with-dynamic-cache-names/154857/1 "2008-12-04T16:14:44Z")

</div>

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](http://mydomain.com/member_name) goes to the  
same action and controller as [http://mydomain.com/other\_member](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
