Class: AwsDevUtils::Backend::Memory

Inherits:
Object
  • Object
show all
Defined in:
lib/aws-dev-utils/backends/memory.rb

Instance Method Summary collapse

Constructor Details

#initializeMemory

Returns a new instance of Memory.



5
6
7
# File 'lib/aws-dev-utils/backends/memory.rb', line 5

def initialize
  @hash = {}
end

Instance Method Details

#get(key) ⇒ Object

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



10
11
12
13
# File 'lib/aws-dev-utils/backends/memory.rb', line 10

def get key
  clean_cache!
  @hash[key][1]
end

#set(key, value, exp) ⇒ Object

Set key to hold the value and set key to timeout after the a given expiration time(in seconds).

Parameters:

  • key (Object)
  • value (Object)
  • exp (Integer)
    • the key-value timeout



19
20
21
22
# File 'lib/aws-dev-utils/backends/memory.rb', line 19

def set key, value, exp
  clean_cache!
  @hash[key] = [Time.now + exp, value]
end