2012-08-09 16:34:56 -07:00
|
|
|
class ItemObserver < ActionController::Caching::Sweeper
|
2012-12-29 22:46:36 -08:00
|
|
|
include FragmentExpiration
|
|
|
|
|
2012-08-09 19:35:30 -07:00
|
|
|
def after_create(item)
|
|
|
|
Rails.logger.debug "Item #{item.id} was just created"
|
|
|
|
expire_newest_items
|
|
|
|
end
|
|
|
|
|
2012-08-09 16:34:56 -07:00
|
|
|
def after_update(item)
|
|
|
|
Rails.logger.debug "Item #{item.id} was just updated"
|
|
|
|
expire_cache_for(item)
|
|
|
|
end
|
|
|
|
|
|
|
|
def after_destroy(item)
|
|
|
|
Rails.logger.debug "Item #{item.id} was just destroyed"
|
|
|
|
expire_cache_for(item)
|
|
|
|
end
|
|
|
|
|
|
|
|
private
|
|
|
|
|
|
|
|
def expire_cache_for(item)
|
2012-12-29 22:46:36 -08:00
|
|
|
expire_fragment("items/#{item.id}#item_link_partial")
|
|
|
|
expire_fragment("items/#{item.id} header")
|
|
|
|
expire_fragment("items/#{item.id} info")
|
2012-08-09 19:35:30 -07:00
|
|
|
end
|
|
|
|
|
|
|
|
def expire_newest_items
|
2012-12-29 22:46:36 -08:00
|
|
|
expire_fragment_in_all_locales('outfits#new newest_items')
|
|
|
|
expire_fragment('items#index newest_items')
|
2012-08-09 16:34:56 -07:00
|
|
|
end
|
|
|
|
end
|