Skip to content
Browse files

only call cache_sweeper on certain methods, use alias_method on callb…

…ack methods
  • Loading branch information...
1 parent bb08948 commit 512d4a1ddb961cad0f83abf17ac0460bcacfcd65 Keavy McMinn committed Jun 30, 2011
View
2 app/controllers/admin/events_controller.rb
@@ -1,7 +1,7 @@
class Admin::EventsController < AdminAreaController
inherit_resources
- cache_sweeper :events_sweeper
+ cache_sweeper :events_sweeper, :only => [:create, :update, :destroy]
def edit
resource.admin_submitted = true
View
2 app/controllers/events_controller.rb
@@ -3,7 +3,7 @@ class EventsController < ApplicationController
before_filter :authenticate, :only => [:edit, :update] unless Rails.env == 'development'
before_filter :check_authorized, :only => [:edit, :update] unless Rails.env == 'development'
- cache_sweeper :events_sweeper
+ cache_sweeper :events_sweeper, :only => [:create, :update, :destroy]
layout :select_layout
View
2 app/controllers/happenings_controller.rb
@@ -5,7 +5,7 @@ class HappeningsController < ApplicationController
before_filter :authenticate unless Rails.env == 'development'
before_filter :check_authorized unless Rails.env == 'development'
- cache_sweeper :events_sweeper
+ cache_sweeper :events_sweeper, :only => [:create, :update, :destroy]
def index
if @event.happenings.blank?
View
28 app/sweepers/events_sweeper.rb
@@ -1,23 +1,13 @@
class EventsSweeper < ActionController::Caching::Sweeper
- observe Event
- observe Happening
+ observe Event, Happening
- def after_create(record)
- expire_cache(record)
+ def expire_cached_content(record)
+ expire_fragment(:fragment => 'events/attend')
+ expire_fragment(:fragment => 'events/speak')
+ expire_fragment(:fragment => 'events/archive')
end
- def after_update(record)
- expire_cache(record)
- end
-
- def after_destroy(record)
- expire_cache(record)
- end
-
- private
- def expire_cache(record)
- expire_fragment 'events/attend'
- expire_fragment 'events/speak'
- expire_fragment 'events/archive'
- end
-end
+ alias_method :after_save, :expire_cached_content
+ alias_method :after_destroy, :expire_cached_content
+ alias_method :after_update, :expire_cached_content
+end

0 comments on commit 512d4a1

Please sign in to comment.
Something went wrong with that request. Please try again.