Class: Mayak::Caching::UnboundedCache

Inherits:
Object
  • Object
show all
Extended by:
T::Generic, T::Helpers, T::Sig
Includes:
Mayak::Cache
Defined in:
lib/mayak/caching/unbounded_cache.rb

Constant Summary collapse

Key =
type_member
Value =
type_member

Instance Method Summary collapse

Constructor Details

#initializeUnboundedCache

Returns a new instance of UnboundedCache.



17
18
19
# File 'lib/mayak/caching/unbounded_cache.rb', line 17

def initialize
  @storage = T.let({}, T::Hash[Key, Value])
end

Instance Method Details

#clearObject



41
42
43
# File 'lib/mayak/caching/unbounded_cache.rb', line 41

def clear
  @storage.clear
end

#delete(key) ⇒ Object



46
47
48
# File 'lib/mayak/caching/unbounded_cache.rb', line 46

def delete(key)
  @storage.delete(key)
end

#fetch(key, &blk) ⇒ Object



32
33
34
35
36
37
38
# File 'lib/mayak/caching/unbounded_cache.rb', line 32

def fetch(key, &blk)
  return T.must(@storage[key]) if @storage.has_key?(key)

  value = blk.call
  @storage[key] = value
  value
end

#read(key) ⇒ Object



22
23
24
# File 'lib/mayak/caching/unbounded_cache.rb', line 22

def read(key)
  @storage[key]
end

#write(key, value) ⇒ Object



27
28
29
# File 'lib/mayak/caching/unbounded_cache.rb', line 27

def write(key, value)
  @storage[key] = value
end