Module: Cachecataz::InstanceMethods
- Defined in:
- lib/cachecataz.rb
Instance Method Summary collapse
-
#cache_key(point_key, indexes = [], scope_hash = {}) ⇒ Object
Instance method to return a cache_key for the class.
-
#cachecataz_index_convert(val) ⇒ String
Determines the intended index conversion for index passed to cache_key.
-
#cachecataz_key(point_key, scope_hash = {}) ⇒ string
Instance method for accessing the cachecataz namespace identifier.
-
#cachecataz_namespace_reset(point_key, scope_hash = {}) ⇒ Object
Instance method to reset a namespace, shouldn’t really be needed, but avail.
-
#expire_all_namespaces(scope_hash = {}) ⇒ Object
Instance method to expire all namespaces for an object.
-
#expire_namespace(point_key, scope_hash = {}) ⇒ Object
Instance method to expire a cachecataz namespace.
Instance Method Details
#cache_key(point_key, indexes = [], scope_hash = {}) ⇒ Object
method removes any index that is already in the namespace definition as it can’t be 2x as unique on the same key
Instance method to return a cache_key for the class
174 175 176 177 178 179 180 |
# File 'lib/cachecataz.rb', line 174 def cache_key(point_key, indexes=[], scope_hash={}) cache_key_point = cachecataz_key(point_key, scope_hash) indexes = [indexes] if !indexes.respond_to?(:each) indexes.uniq! indexes.reject!{ |i| self.class.point_key(point_key).include?(i) } return indexes.inject(cache_key_point){|s, n| s << Cachecataz::Config[:index_delim] << self.cachecataz_index_convert(n) } end |
#cachecataz_index_convert(val) ⇒ String
if index responds to :call then it will check the arity to determine if it is 1, if so it passes self as the argument
Determines the intended index conversion for index passed to cache_key
188 189 190 191 192 193 194 195 196 197 |
# File 'lib/cachecataz.rb', line 188 def cachecataz_index_convert(val) case when val.kind_of?(Symbol) && self.respond_to?(val) self.send(val).to_s when val.respond_to?(:call) val.arity == 1 ? val.call(self).to_s : val.call.to_s else val.to_s end end |
#cachecataz_key(point_key, scope_hash = {}) ⇒ string
Instance method for accessing the cachecataz namespace identifier
158 159 160 161 162 163 |
# File 'lib/cachecataz.rb', line 158 def cachecataz_key(point_key, scope_hash={}) return "cachecataz disabled" if !Cachecataz::Config[:enabled] scope_hash = self.attributes if scope_hash == {} && self.respond_to?(:attributes) return self.class.cache_key(point_key, scope_hash) end |
#cachecataz_namespace_reset(point_key, scope_hash = {}) ⇒ Object
Instance method to reset a namespace, shouldn’t really be needed, but avail
215 216 217 218 |
# File 'lib/cachecataz.rb', line 215 def cachecataz_namespace_reset(point_key, scope_hash={}) scope_hash = self.attributes if scope_hash == {} && self.respond_to?(:attributes) self.class.cachecataz_namespace_reset(point_key, scope_hash) end |
#expire_all_namespaces(scope_hash = {}) ⇒ Object
Instance method to expire all namespaces for an object
209 210 211 212 |
# File 'lib/cachecataz.rb', line 209 def expire_all_namespaces(scope_hash={}) scope_hash = self.attributes if scope_hash == {} && self.respond_to?(:attributes) self.class.expire_all_namespaces(scope_hash) end |
#expire_namespace(point_key, scope_hash = {}) ⇒ Object
Instance method to expire a cachecataz namespace
203 204 205 206 |
# File 'lib/cachecataz.rb', line 203 def expire_namespace(point_key, scope_hash={}) scope_hash = self.attributes if scope_hash == {} && self.respond_to?(:attributes) self.class.expire_namespace(point_key, scope_hash) end |