Public Class methods
new()
Create a new thread safe cache.
[show source]
# File lib/roda/cache.rb 8 def initialize 9 @mutex = Mutex.new 10 @hash = {} 11 end
Public Instance methods
[](key)
Make getting value from underlying hash thread safe.
[show source]
# File lib/roda/cache.rb 14 def [](key) 15 @mutex.synchronize{@hash[key]} 16 end
[]=(key, value)
Make setting value in underlying hash thread safe.
[show source]
# File lib/roda/cache.rb 19 def []=(key, value) 20 @mutex.synchronize{@hash[key] = value} 21 end
freeze()
Return the frozen internal hash. The internal hash can then be accessed directly since it is frozen and there are no thread safety issues.
[show source]
# File lib/roda/cache.rb 26 def freeze 27 @hash.freeze 28 end