Module: Interlock::Finders::ClassMethods
- Defined in:
- lib/interlock/finders.rb
Instance Method Summary collapse
-
#caching_key(id) ⇒ Object
Build the model cache key for a particular id.
-
#find(*args) ⇒ Object
Cached find.
-
#find_all_by_id(*args) ⇒ Object
Cached find_all_by_id.
-
#find_by_id(*args) ⇒ Object
Cached find_by_id.
- #finder_ttl ⇒ Object
Instance Method Details
#caching_key(id) ⇒ Object
Build the model cache key for a particular id.
54 55 56 57 58 59 60 61 |
# File 'lib/interlock/finders.rb', line 54 def caching_key(id) Interlock.caching_key( self.base_class.name, "find", id, "default" ) end |
#find(*args) ⇒ Object
Cached find.
Any other options besides ids short-circuit the cache.
20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/interlock/finders.rb', line 20 def find(*args) return find_via_db(*args) if args.last.is_a? Hash or args.first.is_a? Symbol ids = args.flatten.compact.uniq return find_via_db(ids) if ids.blank? records = find_via_cache(ids, true) if ids.length > 1 or args.first.is_a?(Array) records else records.first end end |
#find_all_by_id(*args) ⇒ Object
Cached find_all_by_id. Ultrasphinx uses this. Short-circuiting works the same as find.
46 47 48 49 |
# File 'lib/interlock/finders.rb', line 46 def find_all_by_id(*args) return method_missing(:find_all_by_id, *args) if args.last.is_a? Hash find_via_cache(args, false) end |
#find_by_id(*args) ⇒ Object
Cached find_by_id. Short-circuiting works the same as find.
38 39 40 41 |
# File 'lib/interlock/finders.rb', line 38 def find_by_id(*args) return method_missing(:find_by_id, *args) if args.last.is_a? Hash find_via_cache(args, false).first end |
#finder_ttl ⇒ Object
63 64 65 |
# File 'lib/interlock/finders.rb', line 63 def finder_ttl 0 end |