Module: Sequel::Plugins::Caching::InstanceMethods

Defined in:
lib/sequel/lib/sequel/plugins/caching.rb

Instance Method Summary collapse

Instance Method Details

#before_updateObject

Remove the object from the cache when updating


80
81
82
83
# File 'lib/sequel/lib/sequel/plugins/caching.rb', line 80

def before_update
  return false if super == false
  cache_delete
end

#cache_keyObject

Return a key unique to the underlying record for caching, based on the primary key value(s) for the object. If the model does not have a primary key, raise an Error.

Raises:


88
89
90
91
92
93
94
95
96
97
# File 'lib/sequel/lib/sequel/plugins/caching.rb', line 88

def cache_key
  raise(Error, "No primary key is associated with this model") unless key = primary_key
  pk = case key
  when Array
    key.collect{|k| @values[k]}
  else
    @values[key] || (raise Error, 'no primary key for this record')
  end
  model.send(:cache_key, pk)
end

#deleteObject

Remove the object from the cache when deleting


100
101
102
103
# File 'lib/sequel/lib/sequel/plugins/caching.rb', line 100

def delete
  cache_delete
  super
end