Class: OpenapiBlocks::Cache

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

Overview

rubocop:disable Style/Documentation

Instance Method Summary collapse

Constructor Details

#initializeCache

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

Returns:

  • (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