Class: Mayak::Caching::UnboundedCache
- Inherits:
-
Object
- Object
- Mayak::Caching::UnboundedCache
- 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
- #clear ⇒ Object
- #delete(key) ⇒ Object
- #fetch(key, &blk) ⇒ Object
-
#initialize ⇒ UnboundedCache
constructor
A new instance of UnboundedCache.
- #read(key) ⇒ Object
- #write(key, value) ⇒ Object
Constructor Details
#initialize ⇒ UnboundedCache
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
#clear ⇒ Object
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 |