Hi experts,
I have built a typical cache sweeper class:
#=====================class PrivilegeCacheSweeper <
ActionController::Caching::Sweeper
observe User
def after_update(user)
expire_cache_for(user)
end
private
def expire_cache_for(user)
p "Hi there!!!"
expire_action(:controller => "users", :action =>
"user_view")
end
end
#=====================
In the UsersController I set:
#=====================class UsersController < ApplicationController
caches_action :user_view
cache_sweeper :privilege_cache_sweeper
def user_view
#code to show list of accessible units of login user
end
def update
#update user
end
end
#=====================
In environment.rb, I already set:
#=====================config.action_controller.perform_caching = true
#=====================
The problem is that after the user is updated, the page "user_view" is
still cached when being refreshed (The output shows "Cached fragment
hit: views/localhost:3000/users/user_view").
The output also shows the text "Hi there!!!" => It means method
"expire_cache_for(user)" is called. However,
"expire_action()" seems not
to work at all.
I also tested the expire_action(:controller => "users", :action
=>
"user_view") by inserting it directly in UsersController::update
method.
It works fine!
Could you give me any suggestion to solve this problem?
My application runs on:
Rails: 2.3.2
Ruby: 1.8
OS: Ubuntu 8.04
Thank you very much.
--
Posted via http://www.ruby-forum.com/.
--
You received this message because you are subscribed to the Google Groups
"Ruby on Rails: Talk" group.
To post to this group, send email to
rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en.
Hi, For whom may get the same problem: I moved the sweeper declaration ''cache_sweeper :privilege_cache_sweeper'' from UsersController to ApplicationController. And it works for me! But I still have no idea why this change makes expire_action in cache sweeper work. Any explanations are welcome. Thanks and regards, .Viet Trung. -- Posted via http://www.ruby-forum.com/. -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Viet, I signed up today just to say you are my savior. I couldn''t figure out why the hell my sweeper wasn''t working either. Thanks for the working fix. -- Posted via http://www.ruby-forum.com/. -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Over two years later .. same problem, same fix, thanks!! But I would also like an answer to the original question .. because i also don''t understand why it only works in the AppController -- Posted via http://www.ruby-forum.com/. -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit https://groups.google.com/groups/opt_out.
On Sun, Dec 9, 2012 at 5:33 PM, Simon K. <lists-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org> wrote:> Over two years later .. same problem, same fix, thanks!! > But I would also like an answer to the original question .. because i > also don''t understand why it only works in the AppController-ENOCONTEXT -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit https://groups.google.com/groups/opt_out.