Class: Isomorfeus::ThreadLocalCache
- Defined in:
- lib/isomorfeus/thread_local_cache.rb
Instance Method Summary collapse
- #[](key) ⇒ Object (also: #fetch)
- #[]=(key, value) ⇒ Object (also: #store)
-
#initialize ⇒ ThreadLocalCache
constructor
A new instance of ThreadLocalCache.
- #key?(key) ⇒ Boolean
Constructor Details
#initialize ⇒ ThreadLocalCache
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
17 18 19 |
# File 'lib/isomorfeus/thread_local_cache.rb', line 17 def key?(key) Thread.current[:local_cache].key?(key) end |