class AwsDevUtils::Backend::Memory

Public Class Methods

new() click to toggle source
# File lib/aws-dev-utils/backends/memory.rb, line 5
def initialize
  @hash = {}
end

Public Instance Methods

get(key) click to toggle source

Get the value of key, if not found, returns nil.

# File lib/aws-dev-utils/backends/memory.rb, line 10
def get key
  clean_cache!
  @hash[key][1]
end
set(key, value, exp) click to toggle source

Set key to hold the value and set key to timeout after the a given expiration time(in seconds). @param key [Object] @param value [Object] @param exp [Integer] - the key-value timeout

# File lib/aws-dev-utils/backends/memory.rb, line 19
def set key, value, exp
  clean_cache!
  @hash[key] = [Time.now + exp, value]
end

Private Instance Methods

clean_cache!() click to toggle source
# File lib/aws-dev-utils/backends/memory.rb, line 26
def clean_cache!
  @hash = @hash.each_with_object({}) do |(k, (exp, v)), acc|
    acc[k] = [exp, v] if Time.now < exp
  end
end