Sha256: 2e5db5ca358c663481e5a278b06632822e6276db7120b31ee0bcb073ef27e440
Contents?: true
Size: 1.28 KB
Versions: 1
Compression:
Stored size: 1.28 KB
Contents
require "persistent-cache/version" require "persistent-cache/storage_api" require "eh/eh" module Persistent class StorageRAM < Persistent::Storage::API attr_accessor :storage def initialize(storage_details = nil) @storage = {} end def save_key_value_pair(serialized_key, serialized_value, timestamp = nil) delete_entry(serialized_key) time_entry = timestamp.nil? ? Time.now.to_s : timestamp.to_s EH.retry!(:args => [serialized_key, serialized_value, time_entry]) do @storage[serialized_key] = {:value => serialized_value, :timestamp => time_entry} end end def lookup_key(serialized_key) EH.retry!(:args => [serialized_key]) do return [] if @storage[serialized_key].nil? [@storage[serialized_key][:value], @storage[serialized_key][:timestamp]] end end def delete_entry(serialized_key) EH.retry!(:args => [serialized_key]) do @storage.delete(serialized_key) end end def size EH.retry!(:args => []) do @storage.size end end def keys EH.retry!(:args => []) do return [] if @storage.keys == [] [@storage.keys] end end def clear EH.retry!(:args => []) do @storage.clear end end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
persistent-cache-storage-ram-0.1.3 | lib/persistent-cache/storage_ram.rb |