Class: ProxES::Container::PluginCache

Inherits:
Object
  • Object
show all
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

Constructor Details

#initializePluginCache

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