Module: Howitzer::Cache

Defined in:
lib/howitzer/cache.rb

Overview

Data can be stored in memory using this class

Constant Summary collapse

SPECIAL_NS_LIST =

:nodoc:

[:cloud].freeze

Class Attribute Summary collapse

Class Method Summary collapse

Class Attribute Details

.dataObject (readonly)

Returns the value of attribute data


11
12
13
# File 'lib/howitzer/cache.rb', line 11

def data
  @data
end

Class Method Details

.clear_all_ns(exception_list = SPECIAL_NS_LIST) ⇒ Object

Deletes all namespaces with data


50
51
52
# File 'lib/howitzer/cache.rb', line 50

def clear_all_ns(exception_list = SPECIAL_NS_LIST)
  (@data.keys - exception_list).each { |ns| clear_ns(ns) }
end

.clear_ns(ns) ⇒ Object

Deletes all data from a namespace


42
43
44
# File 'lib/howitzer/cache.rb', line 42

def clear_ns(ns)
  init_ns(ns)
end

.extract(ns, key = nil) ⇒ Object, Hash

Gets data from memory. Can get all namespace or single data value in namespace using key

Raises:


33
34
35
36
# File 'lib/howitzer/cache.rb', line 33

def extract(ns, key = nil)
  check_ns(ns)
  key ? @data[ns][key] : @data[ns]
end

.store(ns, key, value) ⇒ Object

Saves data into memory. Marking by a namespace and a key

Raises:


20
21
22
23
# File 'lib/howitzer/cache.rb', line 20

def store(ns, key, value)
  check_ns(ns)
  @data[ns][key] = value
end