Module: Rabarber::Core::Cache
Instance Method Summary collapse
- #clear ⇒ Object
- #delete(*roleable_ids) ⇒ Object
- #enabled? ⇒ Boolean
- #fetch(roleable_id, options = { expires_in: 1.hour, race_condition_ttl: 5.seconds }, &block) ⇒ Object
Instance Method Details
#clear ⇒ Object
24 25 26 |
# File 'lib/rabarber/core/cache.rb', line 24 def clear Rails.cache.delete_matched(/^#{CACHE_PREFIX}/o) end |
#delete(*roleable_ids) ⇒ Object
15 16 17 18 |
# File 'lib/rabarber/core/cache.rb', line 15 def delete(*roleable_ids) keys = roleable_ids.map { |roleable_id| key_for(roleable_id) } Rails.cache.delete_multi(keys) if enabled? && keys.any? end |
#enabled? ⇒ Boolean
20 21 22 |
# File 'lib/rabarber/core/cache.rb', line 20 def enabled? Rabarber::Configuration.instance.cache_enabled end |
#fetch(roleable_id, options = { expires_in: 1.hour, race_condition_ttl: 5.seconds }, &block) ⇒ Object
11 12 13 |
# File 'lib/rabarber/core/cache.rb', line 11 def fetch(roleable_id, = { expires_in: 1.hour, race_condition_ttl: 5.seconds }, &block) enabled? ? Rails.cache.fetch(key_for(roleable_id), **, &block) : yield end |