has_cache.rb 472 B

1234567891011121314151617181920
  1. # Copyright (C) 2012-2024 Zammad Foundation, https://zammad-foundation.org/
  2. module ApplicationModel::HasCache
  3. extend ActiveSupport::Concern
  4. included do
  5. after_commit :cache_delete
  6. end
  7. def cache_update(other)
  8. cache_delete if respond_to?(:cache_delete)
  9. other.cache_delete if other.respond_to?(:cache_delete)
  10. ActiveSupport::CurrentAttributes.clear_all
  11. true
  12. end
  13. def cache_delete
  14. Rails.cache.delete("#{self.class}::aws::#{id}")
  15. end
  16. end