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

Defined in:
lib/sequel-cacheable/instance_methods.rb

Instance Method Summary collapse

Instance Method Details

#after_initializeObject



6
7
8
9
# File 'lib/sequel-cacheable/instance_methods.rb', line 6

def after_initialize
  super
  cache! unless id.nil?
end

#after_saveObject



11
12
13
14
# File 'lib/sequel-cacheable/instance_methods.rb', line 11

def after_save
  super
  recache!
end

#cache!Object



21
22
23
# File 'lib/sequel-cacheable/instance_methods.rb', line 21

def cache!
  model.cache_set(cache_key, self)
end

#cache_keyObject



35
36
37
# File 'lib/sequel-cacheable/instance_methods.rb', line 35

def cache_key
  "#{self.id.to_s}"
end

#delete(*args) ⇒ Object



16
17
18
19
# File 'lib/sequel-cacheable/instance_methods.rb', line 16

def delete(*args)
  uncache!
  super
end

#recache!Object



30
31
32
33
# File 'lib/sequel-cacheable/instance_methods.rb', line 30

def recache!
  uncache!
  cache!
end

#to_msgpack(*args) ⇒ Object



39
40
41
# File 'lib/sequel-cacheable/instance_methods.rb', line 39

def to_msgpack(*args)
  msgpack_hash.to_msgpack
end

#uncache!Object



25
26
27
28
# File 'lib/sequel-cacheable/instance_methods.rb', line 25

def uncache!
  model.cache_del(cache_key)
  model.cache_clear(:query)
end