Module: Firebolt::Cache

Includes:
Keys
Included in:
Firebolt
Defined in:
lib/firebolt/cache.rb

Instance Method Summary collapse

Methods included from Keys

#cache_key, #cache_key_with_salt, #namespace, #salt_key

Instance Method Details

#delete(key_suffix, options = nil) ⇒ Object



5
6
7
8
9
10
# File 'lib/firebolt/cache.rb', line 5

def delete(key_suffix, options = nil)
  salted_key = cache_key_with_salt(key_suffix, salt)
  return nil if salted_key.nil?

  ::Firebolt.config.cache.delete(salted_key, options)
end

#fetch(key_suffix, options = nil, &block) ⇒ Object



12
13
14
15
16
17
# File 'lib/firebolt/cache.rb', line 12

def fetch(key_suffix, options = nil, &block)
  salted_key = cache_key_with_salt(key_suffix, salt)
  return nil if salted_key.nil?

  ::Firebolt.config.cache.fetch(salted_key, options, &block)
end

#read(key_suffix, options = nil) ⇒ Object



19
20
21
22
23
24
# File 'lib/firebolt/cache.rb', line 19

def read(key_suffix, options = nil)
  salted_key = cache_key_with_salt(key_suffix, salt)
  return nil if salted_key.nil?

  ::Firebolt.config.cache.read(salted_key, options)
end

#reset_salt!(new_salt) ⇒ Object



26
27
28
# File 'lib/firebolt/cache.rb', line 26

def reset_salt!(new_salt)
  ::Firebolt.config.cache.write(salt_key, new_salt)
end

#saltObject



30
31
32
# File 'lib/firebolt/cache.rb', line 30

def salt
  ::Firebolt.config.cache.read(salt_key)
end

#write(key_suffix, value, options = {}) ⇒ Object



34
35
36
37
38
39
40
# File 'lib/firebolt/cache.rb', line 34

def write(key_suffix, value, options = {})
  salted_key = cache_key_with_salt(key_suffix, salt)
  return nil if salted_key.nil?

  options.merge!(:expires_in => ::Firebolt.config.warming_frequency + 1.hour)
  ::Firebolt.config.cache.write(salted_key, value, options)
end