Module: Cachecataz::ClassMethods

Defined in:
lib/cachecataz.rb

Instance Method Summary collapse

Instance Method Details

#cache_key(point_key, scope_hash) ⇒ String

Takes the cache_point and the value from the cache

Parameters:

  • point_key (Symbol)

    the symbol that identifies the namespace point

  • scope_hash (Hash)

    the hash that provides the data for creating the namespace key

Returns:

  • (String)

    cachecataz namespaced cache key



79
80
81
82
83
# File 'lib/cachecataz.rb', line 79

def cache_key(point_key, scope_hash)
  c_point = cache_point(point_key, scope_hash)
  c_key = Cachecataz[:get, c_point].to_s.strip
  return "#{c_key}#{Cachecataz::Config[:ns_delim]}" << c_point 
end

#cache_point(point_key, scope_hash) ⇒ Object

Determines and returns the cache_point putting i.to_s first in the scope_hash lookup because primarily using with self.attributes in rails which is string keyed



87
88
89
90
91
92
# File 'lib/cachecataz.rb', line 87

def cache_point(point_key, scope_hash)
  c_scope = @_point_keys[point_key]   
  c_point = c_scope.inject(point_key.to_s){|s, i| s << Cachecataz::Config[:ns_delim] << (scope_hash[i.to_s] || scope_hash[i]).to_s }
  Cachecataz[:set, c_point, "0"] if !Cachecataz[:exist?, c_point]
  return c_point
end

#cache_scope(point_key, *c_scope) ⇒ Object

Method used in the Class to defined a cachecataz namespace assigns the scope to a class instance variable with the point_key as key

Parameters:

  • point_key (Symbol)

    the name of the cachecataz namespace

  • c_scope (Array)

    the symbols that defined the scope of the namespace



99
100
101
102
103
104
# File 'lib/cachecataz.rb', line 99

def cache_scope(point_key, *c_scope)
  c_scope.flatten!
  c_scope.uniq!
  c_scope.sort!{|a, b| a.to_s <=> b.to_s}
  @_point_keys[point_key] = c_scope
end

#cachecataz_namespace_reset(point_key, scope_hash = {}) ⇒ Object

Resets a cache namespace to 0, should be needed, but wanted to have something here to do it



124
125
126
127
# File 'lib/cachecataz.rb', line 124

def cachecataz_namespace_reset(point_key, scope_hash={})
  c_point = cache_point(point_key, scope_hash)
  Cachecataz[:set, c_point, "0"]
end

#expire_all_namespaces(scope_hash = {}) ⇒ Object

Class level method to expire all the namespace of cachecataz for a given data provider

Parameters:

  • scope_hash (Hash) (defaults to: {})

    the data provider for the scope of the namespace



119
120
121
# File 'lib/cachecataz.rb', line 119

def expire_all_namespaces(scope_hash={})
  @_point_keys.keys.each{|k| expire_namespace(k, scope_hash)}
end

#expire_namespace(point_key, scope_hash = {}) ⇒ Object

Class level method that expires the namespace in the cache for the point_key and scope data provided

Parameters:

  • point_key (Symbol)
  • scope_hash (Hash) (defaults to: {})

    the data provider for the scope of the namespace



111
112
113
114
# File 'lib/cachecataz.rb', line 111

def expire_namespace(point_key, scope_hash={})
  c_point = cache_point(point_key, scope_hash)
  Cachecataz[:incr, c_point]
end

#point_key(point_key) ⇒ Object

provides access for the point_keys stored in the Class instance variable



130
131
132
# File 'lib/cachecataz.rb', line 130

def point_key(point_key)
  @_point_keys[point_key]
end

#point_keysObject

provides access to all point_keys for the Class



135
136
137
# File 'lib/cachecataz.rb', line 135

def point_keys
  @_point_keys
end