Class: OpenapiBlocks::Cache
- Inherits:
-
Object
- Object
- OpenapiBlocks::Cache
- Defined in:
- lib/openapi_blocks/cache.rb
Overview
rubocop:disable Style/Documentation
Instance Method Summary collapse
- #cached?(key) ⇒ Boolean
- #get(key) ⇒ Object
-
#initialize ⇒ Cache
constructor
A new instance of Cache.
- #invalidate!(key = nil) ⇒ Object
- #set(key, value) ⇒ Object
Constructor Details
#initialize ⇒ Cache
Returns a new instance of Cache.
5 6 7 8 |
# File 'lib/openapi_blocks/cache.rb', line 5 def initialize @store = {} @mutex = Mutex.new end |
Instance Method Details
#cached?(key) ⇒ Boolean
24 25 26 |
# File 'lib/openapi_blocks/cache.rb', line 24 def cached?(key) @store.key?(key) end |
#get(key) ⇒ Object
10 11 12 |
# File 'lib/openapi_blocks/cache.rb', line 10 def get(key) @store[key] end |
#invalidate!(key = nil) ⇒ Object
18 19 20 21 22 |
# File 'lib/openapi_blocks/cache.rb', line 18 def invalidate!(key = nil) @mutex.synchronize do key ? @store.delete(key) : @store.clear end end |
#set(key, value) ⇒ Object
14 15 16 |
# File 'lib/openapi_blocks/cache.rb', line 14 def set(key, value) @mutex.synchronize { @store[key] = value } end |