Module: Cachecataz::ClassMethods
- Defined in:
- lib/cachecataz.rb
Instance Method Summary collapse
-
#cache_key(point_key, scope_hash) ⇒ String
Takes the cache_point and the value from the cache.
-
#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.
-
#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.
-
#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.
-
#expire_all_namespaces(scope_hash = {}) ⇒ Object
Class level method to expire all the namespace of cachecataz for a given data provider.
-
#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.
-
#point_key(point_key) ⇒ Object
provides access for the point_keys stored in the Class instance variable.
-
#point_keys ⇒ Object
provides access to all point_keys for the Class.
Instance Method Details
#cache_key(point_key, scope_hash) ⇒ String
Takes the cache_point and the value from the cache
91 92 93 94 95 |
# File 'lib/cachecataz.rb', line 91 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
99 100 101 102 103 104 |
# File 'lib/cachecataz.rb', line 99 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, Cachecataz::Config[:random] ? rand(10000).to_s : "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
111 112 113 114 115 116 |
# File 'lib/cachecataz.rb', line 111 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
136 137 138 139 |
# File 'lib/cachecataz.rb', line 136 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
131 132 133 |
# File 'lib/cachecataz.rb', line 131 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
123 124 125 126 |
# File 'lib/cachecataz.rb', line 123 def expire_namespace(point_key, scope_hash={}) c_point = cache_point(point_key, scope_hash) Cachecataz[:set, c_point, (Cachecataz[:get, c_point].to_i + 1 rescue rand(10000)).to_s] end |
#point_key(point_key) ⇒ Object
provides access for the point_keys stored in the Class instance variable
142 143 144 |
# File 'lib/cachecataz.rb', line 142 def point_key(point_key) @_point_keys[point_key] end |
#point_keys ⇒ Object
provides access to all point_keys for the Class
147 148 149 |
# File 'lib/cachecataz.rb', line 147 def point_keys @_point_keys end |