Module: Rabarber::Core::Cache
Instance Method Summary collapse
Instance Method Details
#clear ⇒ Object
26 27 28 |
# File 'lib/rabarber/core/cache.rb', line 26 def clear Rails.cache.write(VERSION_KEY, SecureRandom.alphanumeric(8)) end |
#delete(*pairs) ⇒ Object
17 18 19 20 21 22 23 24 |
# File 'lib/rabarber/core/cache.rb', line 17 def delete(*pairs) return unless enabled? && pairs.any? keys = pairs.map { |roleable_id, scope| prepare_key(roleable_id, scope) } Rails.cache.delete_multi(keys) ActiveRecord.after_all_transactions_commit { Rails.cache.delete_multi(keys) } if ActiveRecord::Base.connection.transaction_open? end |
#fetch(roleable_id, scope) ⇒ Object
11 12 13 14 15 |
# File 'lib/rabarber/core/cache.rb', line 11 def fetch(roleable_id, scope, &) return yield unless enabled? Rails.cache.fetch(prepare_key(roleable_id, scope), expires_in: 1.hour, race_condition_ttl: 5.seconds, &) end |