module Howitzer::Cache
Data can be stored in memory using this class
Attributes
Public Class Methods
Deletes all namespaces with data
@param exception_list [Array] a namespace list for excluding
# 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
Deletes all data from a namespace
@param namespace [String] a namespace
# File lib/howitzer/cache.rb, line 42 def clear_ns(namespace) init_ns(namespace) end
Gets data from memory. Can get all namespace or single data value in namespace using key
@param namespace [String] a namespace @param key [String] key that isn’t necessary required @return [Object, Hash] all data from the namespace if the key is ommited, otherwise returs
all data for the namespace
@raise [NoDataError] if the namespace missing
# File lib/howitzer/cache.rb, line 33 def extract(namespace, key = nil) check_ns(namespace) key ? @data[namespace][key] : @data[namespace] end
Saves data into memory. Marking by a namespace and a key
@param namespace [String] a namespace @param key [String] a key that should be uniq within the namespace @param value [Object] everything you want to store in Memory @raise [NoDataError] if the namespace missing
# File lib/howitzer/cache.rb, line 20 def store(namespace, key, value) check_ns(namespace) @data[namespace][key] = value end
Private Class Methods
# File lib/howitzer/cache.rb, line 56 def check_ns(namespace) raise Howitzer::NoDataError, 'Data storage namespace can not be empty' unless namespace init_ns(namespace) if ns_absent?(namespace) end
# File lib/howitzer/cache.rb, line 66 def init_ns(namespace) @data[namespace] = {} end
# File lib/howitzer/cache.rb, line 62 def ns_absent?(namespace) !@data.key?(namespace) end