Skip to content

Instantly share code, notes, and snippets.

@gudleik
Created February 10, 2011 13:17
Show Gist options
  • Save gudleik/820492 to your computer and use it in GitHub Desktop.
Save gudleik/820492 to your computer and use it in GitHub Desktop.
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