Module: CacheQuery
- Extended by:
- ActiveSupport::Concern
- Defined in:
- lib/cache_query.rb,
lib/cache_query/version.rb
Defined Under Namespace
Modules: ClassMethods
Constant Summary collapse
- VERSION =
"0.0.1"
Instance Method Summary collapse
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(name, *args, &block) ⇒ Object
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/cache_query.rb', line 22 def method_missing(name, *args, &block) # you need add touch for association record to flush the cache if name.to_s =~ /cache_((.*)_count)/ && self.respond_to?($2) Rails.cache.fetch([self, $1]) do self.__send__($2).__send__(:count) end elsif name.to_s =~ /cache_(.*)/ && self.respond_to?($1) Rails.cache.fetch([self, $1]) do query_result = self.__send__($1) if query_result.is_a?(ActiveRecord::Relation) query_result.to_a else query_result end end else super end end |
Instance Method Details
#cache_where ⇒ Object
18 19 20 |
# File 'lib/cache_query.rb', line 18 def cache_where # place holder end |