Module: Sequel::Plugins::ActsAsCacheable::InstanceMethods

Defined in:
lib/sequel_acts_as_cacheable.rb

Instance Method Summary collapse

Instance Method Details

#cache!Object



75
76
77
78
79
80
81
82
83
# File 'lib/sequel_acts_as_cacheable.rb', line 75

def cache!
  unless new?
    marshallable!
    if respond_to? :before_cache
      before_cache
    end
    acts_as_cacheable_cache.set model_cache_key, self, acts_as_cacheable_time_to_live
  end
end

#cached?Boolean

Returns:

  • (Boolean)


91
92
93
# File 'lib/sequel_acts_as_cacheable.rb', line 91

def cached?
  acts_as_cacheable_cache.get(model_cache_key).present?
end

#deleteObject



101
102
103
104
105
106
107
108
109
# File 'lib/sequel_acts_as_cacheable.rb', line 101

def delete
  begin
    result = super
  rescue Sequel::NoExistingObject
    logger.error "attempted to delete a record that doesn't exist"
  end
  invalidate_cache!
  result
end

#destroy(opts = {}) ⇒ Object



111
112
113
114
115
# File 'lib/sequel_acts_as_cacheable.rb', line 111

def destroy opts = {}
  result = super opts
  invalidate_cache! unless false == result
  result
end

#save(*columns) ⇒ Object



95
96
97
98
99
# File 'lib/sequel_acts_as_cacheable.rb', line 95

def save *columns
  result = super *columns
  invalidate_cache! if result && !new?
  result
end

#uncache!Object Also known as: invalidate_cache!



85
86
87
# File 'lib/sequel_acts_as_cacheable.rb', line 85

def uncache!
  acts_as_cacheable_cache.delete self.class.model_cache_key id
end