module Sequel::Plugins::Cacheable::InstanceMethods

Public Instance Methods

after_initialize() click to toggle source
Calls superclass method
# File lib/sequel-cacheable/instance_methods.rb, line 6
def after_initialize
  super
  cache! unless id.nil?
end
after_save() click to toggle source
Calls superclass method
# File lib/sequel-cacheable/instance_methods.rb, line 11
def after_save
  super
  recache!
end
cache!() click to toggle source
# File lib/sequel-cacheable/instance_methods.rb, line 21
def cache!
  model.cache_set(cache_key, self)
end
cache_key() click to toggle source
# File lib/sequel-cacheable/instance_methods.rb, line 35
def cache_key
  "#{self.id.to_s}"
end
delete(*args) click to toggle source
Calls superclass method
# File lib/sequel-cacheable/instance_methods.rb, line 16
def delete(*args)
  uncache!
  super
end
recache!() click to toggle source
# File lib/sequel-cacheable/instance_methods.rb, line 30
def recache!
  uncache!
  cache!
end
to_msgpack(*args) click to toggle source
# File lib/sequel-cacheable/instance_methods.rb, line 39
def to_msgpack(*args)
  msgpack_hash.to_msgpack
end
uncache!() click to toggle source
# File lib/sequel-cacheable/instance_methods.rb, line 25
def uncache!
  model.cache_del(cache_key)
  model.cache_clear(:query)
end

Private Instance Methods

msgpack_hash() click to toggle source
# File lib/sequel-cacheable/instance_methods.rb, line 43
def msgpack_hash
  hash = {}
  @values.each_pair do | key, value |
    case value
    when Date
      value = [value.year, value.mon, value.mday, value.start]
    when Sequel::SQLTime, Time
      value = [value.to_i, value.usec]
    when BigDecimal, Bignum
      value = value.to_s
    end
    hash[key] = value
  end
  hash
end