class Roda::RodaCache
A thread safe cache class, offering only []
and []=
methods, each protected by a mutex. Used on non-MRI where Hash is not thread safe.
Public Class Methods
new()
click to toggle source
Create a new thread safe cache.
# File lib/roda.rb, line 18 def initialize @mutex = Mutex.new @hash = {} end
Public Instance Methods
[](key)
click to toggle source
Make getting value from underlying hash thread safe.
# File lib/roda.rb, line 24 def [](key) @mutex.synchronize{@hash[key]} end
[]=(key, value)
click to toggle source
Make setting value in underlying hash thread safe.
# File lib/roda.rb, line 29 def []=(key, value) @mutex.synchronize{@hash[key] = value} end