Skip to content

Instantly share code, notes, and snippets.

@mahemoff
Created April 18, 2012 02:29
Show Gist options
  • Save mahemoff/2410695 to your computer and use it in GitHub Desktop.
Save mahemoff/2410695 to your computer and use it in GitHub Desktop.
model-based Rails sweeper
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