Class: Roda::RodaCache

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

Overview

A thread safe cache class, offering only #[] and #[]= methods, each protected by a mutex.

Instance Method Summary collapse

Constructor Details

#initializeRodaCache

Create a new thread safe cache.



18
19
20
21
# File 'lib/roda.rb', line 18

def initialize
  @mutex = Mutex.new
  @hash = {}
end

Instance Method Details

#[](key) ⇒ Object

Make getting value from underlying hash thread safe.



24
25
26
# File 'lib/roda.rb', line 24

def [](key)
  @mutex.synchronize{@hash[key]}
end

#[]=(key, value) ⇒ Object

Make setting value in underlying hash thread safe.



29
30
31
# File 'lib/roda.rb', line 29

def []=(key, value)
  @mutex.synchronize{@hash[key] = value}
end