Module: Sequel::Plugins::Cacheable::InstanceMethods

Defined in:
lib/sequel-cacheable.rb

Instance Method Summary collapse

Instance Method Details

#after_initializeObject



163
164
165
166
# File 'lib/sequel-cacheable.rb', line 163

def after_initialize
  store_cache unless id.nil?
  super
end

#after_updateObject



168
169
170
171
# File 'lib/sequel-cacheable.rb', line 168

def after_update
  restore_cache
  super
end

#cache_keyObject



197
198
199
# File 'lib/sequel-cacheable.rb', line 197

def cache_key
  "#{self.class.name}::#{self.id.to_s}"
end

#deleteObject



173
174
175
176
# File 'lib/sequel-cacheable.rb', line 173

def delete
  delete_cache
  super
end

#delete_cacheObject



187
188
189
190
# File 'lib/sequel-cacheable.rb', line 187

def delete_cache
  model.cache_del(cache_key)
  model.clear_query_cache
end

#destroy(*args) ⇒ Object



178
179
180
181
# File 'lib/sequel-cacheable.rb', line 178

def destroy(*args)
  delete_cache
  super(*args)
end

#msgpack_hashObject



143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
# File 'lib/sequel-cacheable.rb', line 143

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

#restore_cacheObject



192
193
194
195
# File 'lib/sequel-cacheable.rb', line 192

def restore_cache
  delete_cache
  store_cache
end

#store_cacheObject



183
184
185
# File 'lib/sequel-cacheable.rb', line 183

def store_cache
  model.cache_set(cache_key, self)
end

#to_msgpack(*args) ⇒ Object



159
160
161
# File 'lib/sequel-cacheable.rb', line 159

def to_msgpack(*args)
  msgpack_hash.to_msgpack
end