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?(method, include_private = false) ⇒ Boolean
:nodoc:.
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method, *args, &block) ⇒ Object (protected)
:nodoc:
60 61 62 63 64 65 66 67 |
# File 'lib/arid_cache/active_record.rb', line 60 def method_missing(method, *args, &block) #:nodoc: if method.to_s =~ /^cached_(.*)$/ opts = args.empty? ? {} : args.first AridCache.lookup(self, $1, opts, &block) else super end end |
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'
33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/arid_cache/active_record.rb', line 33 def arid_cache_key(key, ={}) object_key = if self.is_a?(Class) self.name.downcase elsif [:auto_expire] self.cache_key else result = "#{AridCache::Inflector.pluralize(self.class.name.downcase)}" result += "/#{self[:id]}" if self.respond_to?(:[]) && !self[:id].nil? result end 'arid-cache-' + object_key + '-' + key.to_s end |
#clear_caches ⇒ Object
10 11 12 13 |
# File 'lib/arid_cache/active_record.rb', line 10 def clear_caches AridCache.cache.clear_class_caches(self) AridCache.cache.clear_instance_caches(self) end |
#clear_class_caches ⇒ Object
15 16 17 |
# File 'lib/arid_cache/active_record.rb', line 15 def clear_class_caches AridCache.cache.clear_class_caches(self) end |
#clear_instance_caches ⇒ Object
19 20 21 |
# File 'lib/arid_cache/active_record.rb', line 19 def clear_instance_caches AridCache.cache.clear_instance_caches(self) end |
#respond_to?(method, include_private = false) ⇒ Boolean
:nodoc:
46 47 48 49 50 51 52 53 54 55 56 |
# File 'lib/arid_cache/active_record.rb', line 46 def respond_to?(method, include_private = false) #:nodoc: if (method.to_s =~ /^cached_.*(_count)?$/).nil? super(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 super end end |