Class: Split::Cache

Inherits:
Object
  • Object
show all
Defined in:
lib/split/cache.rb

Class Method Summary collapse

Class Method Details

.clearObject



5
6
7
# File 'lib/split/cache.rb', line 5

def self.clear
  @cache = nil
end

.clear_key(key) ⇒ Object



21
22
23
24
25
# File 'lib/split/cache.rb', line 21

def self.clear_key(key)
  @cache&.keys&.each do |namespace|
    @cache[namespace]&.delete(key)
  end
end

.fetch(namespace, key) ⇒ Object



9
10
11
12
13
14
15
16
17
18
19
# File 'lib/split/cache.rb', line 9

def self.fetch(namespace, key)
  return yield unless Split.configuration.cache

  @cache ||= {}
  @cache[namespace] ||= {}

  value = @cache[namespace][key]
  return value if value

  @cache[namespace][key] = yield
end