Created
February 10, 2011 13:17
-
-
Save gudleik/820492 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Foo < Apotomo::Widget | |
cache :display, :my_cache_key | |
def my_cache_key | |
{ :site_id => current_site.id, | |
:article_id => @opts[:id] | |
} | |
end | |
end | |
class Bar < Apotomo::Widget | |
cache :display, :my_cache_key | |
def my_cache_key | |
{ :project_id => current_project.id, | |
:user_id => current_user.id, | |
:size => @opts[:size], | |
} | |
end | |
end | |
class MySweeper < ActionController::Caching::Sweeper | |
observe FooModel, BarModel | |
def after_update(record) | |
widget = case | |
when record.is_a?(FooModel) then :foo | |
when record.is_a?(BarModel) then :bar | |
end | |
key = send(:"#{widget}_cache_key", record) | |
expire_cell_state widget, :display, key | |
end | |
def foo_cache_key(record) | |
{ :site_id => current_site.id, | |
:article_id => record.id | |
} | |
end | |
def bar_cache_key(record) | |
{ :project_id => record.project.id, | |
:user_id => current_user.id, | |
:size => "wtf, the sweeper knows nothing about this" | |
} | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment