class Caching::Storage

Public Class Methods

new() click to toggle source
# File lib/caching/storage.rb, line 4
def initialize
  @storage = Concurrent::Hash.new
  @lock = Mutex.new
end

Public Instance Methods

clear(*keys) click to toggle source
# File lib/caching/storage.rb, line 21
def clear(*keys)
  if keys.empty?
    @storage = {}
  else
    keys.each { |k| @storage.delete k }
  end
end
fetch(key) { || ... } click to toggle source
# File lib/caching/storage.rb, line 17
def fetch(key)
  read(key) || write(key, yield)
end
read(key) click to toggle source
# File lib/caching/storage.rb, line 9
def read(key)
   @storage[key]
end
write(key, value) click to toggle source
# File lib/caching/storage.rb, line 13
def write(key, value)
  @storage[key] = value
end