caching - Expiring all caches on a controller -
i got resourceful controller custom action. action pretty heavy, i'm working on caching it:
class mycontroller < applicationcontroller caches_action :walk_to_mordor # /my/:id/walk_to_mordor/:direction def walk_to_mordor # srz bzns end end
it works nice, caching done , page fast. however, want allow user "bust" cache clicking on link on page. @ first tried:
def bust_cache expire_action :action => :walk_to_mordor end
rails complained no route matches action. might because of parameter. hmm, let's give him:
def bust_cache myentities.all.each |e| expire_action walk_to_mordor_path(e, ??) end end
problem, can't possibly identify choices of :direction
.
is there way clear action caches match regular expression, or action caches specific controller?
the secret called expire_fragment
:
expire_fragment(key, options = nil)
removes fragments cache.
key can take 1 of 3 forms:
string - take form of path, "pages/45/notes".
hash - treated implicit call
url_for
,{:controller => "pages", :action => "notes", :id => 45}
regexp - remove fragment matches,
%r{pages/d*/notes}
might remove notes. make sure don’t use anchors in regex (^
or$
) because actual filename matched looks./cache/filename/path.cache
. note: regexp expiration supported on caches can iterate on keys (unlike memcached).
http://api.rubyonrails.org/classes/actioncontroller/caching/fragments.html#method-i-expire_fragment
sadly, won't work memcached (if ever decide use it). gotta lot more clever avoid cache in circunstance. maybe adding serial
parameter request, , increment when user presses 'bust cache' button...
Comments
Post a Comment