Module: AridCache::ActiveRecord::MirrorMethods
- Defined in:
- lib/arid_cache/active_record.rb
Instance Method Summary collapse
-
#arid_cache_key(key, options = {}) ⇒ Object
Return an AridCache key for the given key fragment for this object.
- #clear_caches ⇒ Object
- #clear_class_caches ⇒ Object
- #clear_instance_caches ⇒ Object
-
#respond_to_with_arid_cache?(method, include_private = false) ⇒ Boolean
:nodoc:.
Instance Method Details
#arid_cache_key(key, options = {}) ⇒ Object
Return an AridCache key for the given key fragment for this object.
Supported options:
:auto_expire => true/false # (default false) whether or not to use the <tt>cache_key</tt> method on instance caches
Examples:
User.arid_cache_key('companies') => 'user-companies'
User.first.arid_cache_key('companies') => 'users/1-companies'
User.first.arid_cache_key('companies', :auto_expire => true) => 'users/20090120091123-companies'
41 42 43 44 45 46 47 48 49 50 |
# File 'lib/arid_cache/active_record.rb', line 41 def arid_cache_key(key, ={}) object_key = if self.is_a?(Class) self.name.downcase elsif [:auto_expire] self.cache_key else "#{self.class.name.downcase.pluralize}/#{self.id}" end 'arid-cache-' + object_key + '-' + key.to_s end |
#clear_caches ⇒ Object
18 19 20 21 |
# File 'lib/arid_cache/active_record.rb', line 18 def clear_caches AridCache.cache.clear_class_caches(self) AridCache.cache.clear_instance_caches(self) end |
#clear_class_caches ⇒ Object
23 24 25 |
# File 'lib/arid_cache/active_record.rb', line 23 def clear_class_caches AridCache.cache.clear_class_caches(self) end |
#clear_instance_caches ⇒ Object
27 28 29 |
# File 'lib/arid_cache/active_record.rb', line 27 def clear_instance_caches AridCache.cache.clear_instance_caches(self) end |
#respond_to_with_arid_cache?(method, include_private = false) ⇒ Boolean
:nodoc:
52 53 54 55 56 57 58 59 60 61 62 |
# File 'lib/arid_cache/active_record.rb', line 52 def respond_to_with_arid_cache?(method, include_private = false) #:nodoc: if (method.to_s =~ /^cached_.*(_count)?$/).nil? respond_to_without_arid_cache?(method, include_private) elsif method.to_s =~ /^cached_(.*)_count$/ AridCache.store.has?(self, "#{$1}_count") || AridCache.store.has?(self, $1) || super("#{$1}_count", include_private) || super($1, include_private) elsif method.to_s =~ /^cached_(.*)$/ AridCache.store.has?(self, $1) || super($1, include_private) else respond_to_without_arid_cache?(method, include_private) end end |