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(namespace) ⇒ Object

Deletes all data from a namespace

Parameters:

  • namespace (String)

    a namespace



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

def clear_ns(namespace)
  init_ns(namespace)
end

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

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

Parameters:

  • namespace (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(namespace, key = nil)
  check_ns(namespace)
  key ? @data[namespace][key] : @data[namespace]
end

.store(namespace, key, value) ⇒ Object

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

Parameters:

  • namespace (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(namespace, key, value)
  check_ns(namespace)
  @data[namespace][key] = value
end