Module: Sequel::Plugins::ActsAsCacheable::InstanceMethods
- Defined in:
- lib/sequel_acts_as_cacheable.rb
Instance Method Summary collapse
- #cache! ⇒ Object
- #cached? ⇒ Boolean
- #delete ⇒ Object
- #destroy(opts = {}) ⇒ Object
- #save(*columns) ⇒ Object
- #uncache! ⇒ Object (also: #invalidate_cache!)
Instance Method Details
#cache! ⇒ Object
80 81 82 83 84 85 86 87 88 |
# File 'lib/sequel_acts_as_cacheable.rb', line 80 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
96 97 98 |
# File 'lib/sequel_acts_as_cacheable.rb', line 96 def cached? acts_as_cacheable_cache.get(model_cache_key).present? end |
#delete ⇒ Object
106 107 108 109 110 111 112 113 114 115 116 |
# File 'lib/sequel_acts_as_cacheable.rb', line 106 def delete begin result = super rescue Sequel::NoExistingObject if acts_as_cacheable_logger acts_as_cacheable_logger.error "attempted to delete a record that doesn't exist" end end invalidate_cache! result end |
#destroy(opts = {}) ⇒ Object
118 119 120 121 122 |
# File 'lib/sequel_acts_as_cacheable.rb', line 118 def destroy opts = {} result = super opts invalidate_cache! unless false == result result end |
#save(*columns) ⇒ Object
100 101 102 103 104 |
# File 'lib/sequel_acts_as_cacheable.rb', line 100 def save *columns result = super *columns invalidate_cache! if result && !new? result end |
#uncache! ⇒ Object Also known as: invalidate_cache!
90 91 92 |
# File 'lib/sequel_acts_as_cacheable.rb', line 90 def uncache! acts_as_cacheable_cache.delete self.class.model_cache_key id end |