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

Parameters:

  • exception_list (Array) (defaults to: SPECIAL_NS_LIST)

    a namespace list for excluding



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

Parameters:

  • ns (String)

    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

Parameters:

  • ns (String)

    a namespace

  • key (String) (defaults to: nil)

    key that isn’t necessary required

Returns:

  • (Object, Hash)

    all data from the namespace if the key is ommited, otherwise returs all data for the namespace

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

Parameters:

  • ns (String)

    a namespace

  • key (String)

    a key that should be uniq within the namespace

  • value (Object)

    everything you want to store in Memory

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