has_cache.rb 504 B

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