# File lib/sequel-cacheable/class_methods.rb, line 12 def primary_key_lookup(id) cache_fetch(id.to_s) do super end end
module Sequel::Plugins::Cacheable::ClassMethods
Attributes
cache_driver[R]
cache_options[R]
caches[R]
Public Instance Methods
cache_clear(type)
click to toggle source
# File lib/sequel-cacheable/class_methods.rb, line 69 def cache_clear(type) @caches[type].dup.each {|key| cache_del(key) } end
cache_del(key)
click to toggle source
# File lib/sequel-cacheable/class_methods.rb, line 64 def cache_del(key) @caches[key.match(/\AQuery:/) ? :query : :instance].delete(key) cache_driver.del(cache_key(key)) end
cache_fetch(key, ttl = @cache_options[:ttl], &block)
click to toggle source
# File lib/sequel-cacheable/class_methods.rb, line 59 def cache_fetch(key, ttl = @cache_options[:ttl], &block) @caches[key.match(/\AQuery:/) ? :query : :instance] << key cache_driver.fetch(cache_key(key), ttl, &block) end
cache_get(key)
click to toggle source
# File lib/sequel-cacheable/class_methods.rb, line 55 def cache_get(key) restore_by_cache(cache_driver.get(cache_key(key))) end
cache_key(key)
click to toggle source
# File lib/sequel-cacheable/class_methods.rb, line 46 def cache_key(key) "#{self.name}:#{key}" end
cache_set(key, value, ttl = @cache_options[:ttl])
click to toggle source
# File lib/sequel-cacheable/class_methods.rb, line 50 def cache_set(key, value, ttl = @cache_options[:ttl]) @caches[key.match(/\AQuery:/) ? :query : :instance] << key cache_driver.set(cache_key(key), value, ttl) end
inherited(subclass)
click to toggle source
Calls superclass method
# File lib/sequel-cacheable/class_methods.rb, line 8 def inherited(subclass) super end
primary_key_lookup(id)
click to toggle source
Calls superclass method
restore_by_cache(hash)
click to toggle source
# File lib/sequel-cacheable/class_methods.rb, line 18 def restore_by_cache(hash) return nil if hash.nil? return hash.map{|hs| restore_by_cache(hs) } if hash.is_a?(Array) return hash if hash.kind_of?(Sequel::Model) hash.keys.each do | key | value = hash.delete(key) key = key.to_sym rescue key case db_schema[key][:type] when :date value = Date.new(*value) when :time value = Sequel::SQLTime.at(value[0], value[1]) when :datetime value = Time.at(value[0], value[1]) when :decimal value = BigDecimal.new(value) when :integer value = value.to_i end hash[key] = value end return new(hash, true) end