class I18n::Tasks::Concurrent::Cache
A thread-safe cache. @since 0.9.25
Public Class Methods
new()
click to toggle source
# File lib/i18n/tasks/concurrent/cache.rb, line 9 def initialize @mutex = Mutex.new @map = {} end
Public Instance Methods
fetch(key, &block)
click to toggle source
@param [Object] key @return [Object] Cached or computed value.
# File lib/i18n/tasks/concurrent/cache.rb, line 16 def fetch(key, &block) @mutex.synchronize do @map[key] ||= CachedValue.new(&block) end.get end