The rails app has the following sweeper:
class AgencyEquipmentTypeSweeper < ActionController::Caching::Sweeper observe AgencyEquipmentType
We would like to extract the after_update, after_delete and after_create callbacks into a module called "ExpireOptions"
The module should look like this (using the 'expire_options' method remaining in the original sweeper):
module ExpireOptions def after_update(record) expire_options(record) end def after_delete(record) expire_options(record) end def after_create(record) expire_options(record) end end class AgencyEquipmentTypeSweeper < ActionController::Caching::Sweeper observe AgencyEquipmentType include ExpireOptions def expire_options(agency_equipment_type) Rails.cache.delete("agency_equipment_type_options/#{agency_equipment_type.agency_id}") end end
BUT, cache expiration works only if we define methods explicitly in the sweeper. Is there an easy way to extract these callback methods into a module and still work with them?
source share