zammad_file_store.rb 1.1 KB

1234567891011121314151617181920212223242526272829303132333435
  1. # Copyright (C) 2012-2024 Zammad Foundation, https://zammad-foundation.org/
  2. module ActiveSupport
  3. module Cache
  4. class ZammadFileStore < FileStore
  5. def write(name, value, options = {})
  6. # in certain cases, caches are deleted by other thread at same
  7. # time, just log it
  8. super
  9. rescue Errno::ENOENT => e
  10. Rails.logger.debug { "Can't write cache (probably related to high load / https://github.com/zammad/zammad/issues/3685) #{name}: #{e.inspect}" }
  11. Rails.logger.debug e
  12. rescue => e
  13. Rails.logger.error "Can't write cache #{name}: #{e.inspect}"
  14. Rails.logger.error e
  15. end
  16. alias clear_original clear
  17. # Running systems can access the caches while clearing so it can
  18. # lead to exceptions. The retry will help to stabilize this a bit.
  19. def clear
  20. retries = 0
  21. begin
  22. clear_original
  23. rescue
  24. sleep 0.5
  25. retries += 1
  26. retry if retries < 3
  27. Rails.logger.error 'Rails.cache.clear failed 3 times to clear the zammad file store.'
  28. end
  29. end
  30. end
  31. end
  32. end