saasbook

movie_sweeper.rb

Apr 4th, 2012
389
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 0.50 KB | None | 0 0
  1. class MovieSweeper < ActionController::Caching::Sweeper
  2.   observe Movie
  3.   # if a movie is created or deleted, movie list becomes invalid
  4.   #   and rendered partials become invalid
  5.   def after_save(movie)    ; invalidate ; end
  6.   def after_destroy(movie) ; invalidate ; end
  7.   private
  8.   def invalidate
  9.     expire_action :action => ['index', 'show']
  10.     expire_fragment 'movies_with_ratings'
  11.   end
  12. end
  13.  
  14. # IMPORTANT: must add following to top of MoviesController:
  15. cache_sweeper :movie_sweeper
  16. caches_action :index, :show
Add Comment
Please, Sign In to add comment