Class: Trocla::Stores::Memory
- Inherits:
-
Trocla::Store
- Object
- Trocla::Store
- Trocla::Stores::Memory
- Defined in:
- lib/trocla/stores/memory.rb
Overview
a simple in memory store just as an example
Instance Attribute Summary collapse
-
#memory ⇒ Object
readonly
Returns the value of attribute memory.
Attributes inherited from Trocla::Store
Instance Method Summary collapse
- #formats(key) ⇒ Object
- #get(key, format) ⇒ Object
-
#initialize(config, trocla) ⇒ Memory
constructor
A new instance of Memory.
- #search(key) ⇒ Object
- #set(key, format, value, options = {}) ⇒ Object
Methods inherited from Trocla::Store
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
#memory ⇒ Object (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, = {}) super(key, format, value, ) set_expires(key, ['expires']) end |