1
0
Fork 0
forked from OpenNeo/impress
impress/app/models/item_observer.rb

32 lines
849 B
Ruby
Raw Normal View History

class ItemObserver < ActionController::Caching::Sweeper
include FragmentExpiration
def after_create(item)
Rails.logger.debug "Item #{item.id} was just created"
expire_newest_items
end
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)
2013-06-07 13:26:51 -07:00
expire_fragment_in_all_locales("items/#{item.id}#item_link_partial")
expire_fragment_in_all_locales("items/#{item.id} header")
expire_fragment_in_all_locales("items/#{item.id} info")
end
def expire_newest_items
expire_fragment_in_all_locales('outfits#new newest_items')
expire_fragment_in_all_locales('items#index newest_items')
end
end