Created
April 18, 2012 02:29
-
-
Save mahemoff/2410695 to your computer and use it in GitHub Desktop.
model-based Rails sweeper
This file contains hidden or 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 EpisodeSweeper < ActionController::Caching::Sweeper | |
observe Series, Episode | |
def after_create(record) expire_series_episodes_cache(record) ; end | |
def after_update(record) expire_series_episodes_cache(record) ; end | |
def after_destroy(record) expire_series_episodes_cache(record) ; end | |
def expire_series_episodes_cache(record) | |
series = record.is_a?(Series) ? record : record.series | |
ActionController::Base.new.expire_fragment "series/#{series.id}/episodes" | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment