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.



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

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

#formats(key) ⇒ Object



24
25
26
# File 'lib/trocla/stores/memory.rb', line 24

def formats(key)
  memory[key].empty? ? nil : memory[key].keys
end

#get(key, format) ⇒ Object



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

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

#search(key) ⇒ Object



28
29
30
31
# File 'lib/trocla/stores/memory.rb', line 28

def search(key)
  r = memory.keys.grep(/#{key}/)
  r.empty? ? nil : r
end

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



19
20
21
22
# File 'lib/trocla/stores/memory.rb', line 19

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