class Drydock::ObjectCaches::InMemoryCache

Public Class Methods

new() click to toggle source
# File lib/drydock/object_caches/in_memory_cache.rb, line 8
def initialize
  @mem = {}
end

Public Instance Methods

clear() click to toggle source
# File lib/drydock/object_caches/in_memory_cache.rb, line 12
def clear
  @mem.clear
  true
end
fetch(key, &blk) click to toggle source
# File lib/drydock/object_caches/in_memory_cache.rb, line 17
def fetch(key, &blk)
  @mem.fetch(key, &blk)
end
get(key, &blk) click to toggle source
# File lib/drydock/object_caches/in_memory_cache.rb, line 21
def get(key, &blk)
  if @mem.key?(key)
    if blk.nil?
      @mem[key]
    else
      blk.call(StringIO.new(@mem[key]))
    end
  else
    nil
  end
end
key?(key) click to toggle source
# File lib/drydock/object_caches/in_memory_cache.rb, line 33
def key?(key)
  @mem.key?(key)
end
set(key, value = nil, &blk) click to toggle source
# File lib/drydock/object_caches/in_memory_cache.rb, line 37
def set(key, value = nil, &blk)
  if blk
    buffer = StringIO.new
    blk.call buffer
    buffer.rewind
    @mem[key] = buffer.string
  else
    @mem[key] = value
  end

  nil
end