Class: ProxES::Container::PluginCache
- Inherits:
-
Object
- Object
- ProxES::Container::PluginCache
- Defined in:
- lib/proxes/container.rb
Overview
A thread safe cache class, offering only #[] and #[]= methods, each protected by a mutex. Ripped off from Roda - github.com/jeremyevans/roda
Instance Method Summary collapse
-
#[](key) ⇒ Object
Make getting value from underlying hash thread safe.
-
#[]=(key, value) ⇒ Object
Make setting value in underlying hash thread safe.
-
#initialize ⇒ PluginCache
constructor
Create a new thread safe cache.
- #inject(memo, &block) ⇒ Object
- #map(&block) ⇒ Object
Constructor Details
#initialize ⇒ PluginCache
Create a new thread safe cache.
10 11 12 13 |
# File 'lib/proxes/container.rb', line 10 def initialize @mutex = Mutex.new @hash = {} end |
Instance Method Details
#[](key) ⇒ Object
Make getting value from underlying hash thread safe.
16 17 18 |
# File 'lib/proxes/container.rb', line 16 def [](key) @mutex.synchronize { @hash[key] } end |
#[]=(key, value) ⇒ Object
Make setting value in underlying hash thread safe.
21 22 23 |
# File 'lib/proxes/container.rb', line 21 def []=(key, value) @mutex.synchronize { @hash[key] = value } end |
#inject(memo, &block) ⇒ Object
29 30 31 |
# File 'lib/proxes/container.rb', line 29 def inject(memo, &block) @mutex.synchronize { @hash.inject(memo, &block) } end |
#map(&block) ⇒ Object
25 26 27 |
# File 'lib/proxes/container.rb', line 25 def map(&block) @mutex.synchronize { @hash.map(&block) } end |