Class: Trocla::Stores::Memory

Inherits:
Trocla::Store show all
Defined in:
lib/trocla/stores/memory.rb

Overview

a simple in memory store just as an example

Instance Attribute Summary collapse

Attributes inherited from Trocla::Store

#store_config, #trocla

Instance Method Summary collapse

Methods inherited from Trocla::Store

#close, #delete

Constructor Details

#initialize(config, trocla) ⇒ Memory

Returns a new instance of Memory.



4
5
6
7
# File 'lib/trocla/stores/memory.rb', line 4

def initialize(config,trocla)
  super(config,trocla)
  @memory = Hash.new({})
end

Instance Attribute Details

#memoryObject (readonly)

Returns the value of attribute memory.



3
4
5
# File 'lib/trocla/stores/memory.rb', line 3

def memory
  @memory
end

Instance Method Details

#get(key, format) ⇒ Object



9
10
11
12
13
14
15
16
# File 'lib/trocla/stores/memory.rb', line 9

def get(key,format)
  unless expired?(key)
    memory[key][format]
  else
    delete_all(key)
    nil
  end
end

#set(key, format, value, options = {}) ⇒ Object



17
18
19
20
# File 'lib/trocla/stores/memory.rb', line 17

def set(key,format,value,options={})
  super(key,format,value,options)
  set_expires(key,options['expires'])
end