Class: ActionMailer::Base
- Inherits:
-
Object
- Object
- ActionMailer::Base
- Defined in:
- lib/action_mailer_cache_delivery/action_mailer/base.rb
Class Method Summary collapse
-
.cached_deliveries ⇒ Array
Returns an array of delivered mails.
-
.clear_cache ⇒ Object
Clears delivered mails.
-
.with_cache_lock(file) ⇒ Object
private
Locks file to prevent concurrent mail jobs from race condition.
Class Method Details
.cached_deliveries ⇒ Array
Returns an array of delivered mails.
10 11 12 13 14 15 16 17 18 19 20 |
# File 'lib/action_mailer_cache_delivery/action_mailer/base.rb', line 10 def cached_deliveries with_cache_lock("#{cache_settings[:location]}.lock") do if File.exist?(cache_settings[:location]) File.open(cache_settings[:location], 'r') do |file| Marshal.load(file) end else [] end end end |
.clear_cache ⇒ Object
Clears delivered mails.
It also cleans ActionMailer::Base.deliveries
27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/action_mailer_cache_delivery/action_mailer/base.rb', line 27 def clear_cache with_cache_lock("#{cache_settings[:location]}.lock") do deliveries.clear if File.exist?(cache_settings[:location]) File.open(cache_settings[:location], 'w') do |file| Marshal.dump(deliveries, file) end end end end |
.with_cache_lock(file) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Locks file to prevent concurrent mail jobs from race condition.
43 44 45 46 47 48 49 50 |
# File 'lib/action_mailer_cache_delivery/action_mailer/base.rb', line 43 def with_cache_lock(file) lockfile = File.open(file, 'w') lockfile.flock(File::LOCK_EX) yield ensure lockfile.flock(File::LOCK_UN) lockfile.close end |