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
162 163 164 165 166 167 168 |
# File 'lib/cachecataz.rb', line 162 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
176 177 178 179 180 181 182 183 184 185 |
# File 'lib/cachecataz.rb', line 176 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
146 147 148 149 150 151 |
# File 'lib/cachecataz.rb', line 146 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
203 204 205 206 |
# File 'lib/cachecataz.rb', line 203 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
197 198 199 200 |
# File 'lib/cachecataz.rb', line 197 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
191 192 193 194 |
# File 'lib/cachecataz.rb', line 191 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 |