Class: Isomorfeus::ThreadLocalCache

Inherits:
Object
  • Object
show all
Defined in:
lib/isomorfeus/thread_local_cache.rb

Instance Method Summary collapse

Constructor Details

#initializeThreadLocalCache

Returns a new instance of ThreadLocalCache.



3
4
5
# File 'lib/isomorfeus/thread_local_cache.rb', line 3

def initialize
  Thread.current[:local_cache] = {} unless Thread.current.key?(:local_cache)
end

Instance Method Details

#[](key) ⇒ Object Also known as: fetch



7
8
9
# File 'lib/isomorfeus/thread_local_cache.rb', line 7

def [](key)
  Thread.current[:local_cache][key]
end

#[]=(key, value) ⇒ Object Also known as: store



12
13
14
# File 'lib/isomorfeus/thread_local_cache.rb', line 12

def []=(key, value)
  Thread.current[:local_cache][key] = value
end

#key?(key) ⇒ Boolean

Returns:

  • (Boolean)


17
18
19
# File 'lib/isomorfeus/thread_local_cache.rb', line 17

def key?(key)
  Thread.current[:local_cache].key?(key)
end