Module: Rabarber::Core::Cache

Extended by:
Cache
Included in:
Cache
Defined in:
lib/rabarber/core/cache.rb

Instance Method Summary collapse

Instance Method Details

#clearObject



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

Returns:

  • (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, options = { expires_in: 1.hour, race_condition_ttl: 5.seconds }, &block)
  enabled? ? Rails.cache.fetch(key_for(roleable_id), **options, &block) : yield
end