Sha256: 4e529e6d3b87e19f4af1ebecfca7e1939cd94d7850c8389d9c4e1a5db2dd543f
Contents?: true
Size: 567 Bytes
Versions: 1
Compression:
Stored size: 567 Bytes
Contents
require 'concurrent/map' module Safelylaunch class HttpCache Value = Struct.new(:expired_time, :data) def initialize @hash = Concurrent::Map.new end def put(key, payload, expired_in) @hash.put_if_absent(key, Value.new(Time.new.to_i + expired_in, payload)) payload end def get(key) value = @hash[key] if value && (Time.new.to_i < value.expired_time) value.data else @hash.delete(key) nil end end # only for tests def keys @hash.keys end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
safelylaunch-0.1.0 | lib/safelylaunch/http_cache.rb |