Module: Sequel::Plugins::Cacheable::DatasetMethods
- Defined in:
- lib/sequel-cacheable/dataset_methods.rb
Instance Method Summary collapse
Instance Method Details
#all(*args, &block) ⇒ Object
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 |
# File 'lib/sequel-cacheable/dataset_methods.rb', line 6 def all(*args, &block) if( model && model.respond_to?(:cache_fetch) && model.[:query_cache] && @row_proc.kind_of?(Class) && @row_proc.included_modules.include?(Sequel::Model::InstanceMethods) ) @row_proc.cache_fetch(cache_key) do super(*args, &block) end else super(*args, &block) end end |
#cache_key ⇒ Object
48 49 50 |
# File 'lib/sequel-cacheable/dataset_methods.rb', line 48 def cache_key "Query:#{select_sql.gsub(/ +/, '_')}" end |
#first(*args) ⇒ Object
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/sequel-cacheable/dataset_methods.rb', line 22 def first(*args) if( model && model.respond_to?(:cache_fetch) && model.[:query_cache] && @row_proc.kind_of?(Class) && @row_proc.included_modules.include?(Sequel::Model::InstanceMethods) ) @row_proc.cache_fetch("#{cache_key}:first") do super(*args) end else super(*args) end end |
#with_pk(pk) ⇒ Object
38 39 40 41 42 43 44 45 46 |
# File 'lib/sequel-cacheable/dataset_methods.rb', line 38 def with_pk(pk) if pk.is_a(Integer) model.cache_fetch(pk.to_s) do super(pk) end else super(pk) end end |