Module: Sequel::Plugins::Cacheable::InstanceMethods
- Defined in:
- lib/sequel-cacheable.rb
Instance Method Summary collapse
- #after_initialize ⇒ Object
- #after_update ⇒ Object
- #cache_key ⇒ Object
- #delete ⇒ Object
- #delete_cache ⇒ Object
- #destroy(*args) ⇒ Object
- #msgpack_hash ⇒ Object
- #restore_cache ⇒ Object
- #store_cache ⇒ Object
- #to_msgpack(*args) ⇒ Object
Instance Method Details
#after_initialize ⇒ Object
163 164 165 166 |
# File 'lib/sequel-cacheable.rb', line 163 def after_initialize store_cache unless id.nil? super end |
#after_update ⇒ Object
168 169 170 171 |
# File 'lib/sequel-cacheable.rb', line 168 def after_update restore_cache super end |
#cache_key ⇒ Object
197 198 199 |
# File 'lib/sequel-cacheable.rb', line 197 def cache_key "#{self.class.name}::#{self.id.to_s}" end |
#delete ⇒ Object
173 174 175 176 |
# File 'lib/sequel-cacheable.rb', line 173 def delete delete_cache super end |
#delete_cache ⇒ Object
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_hash ⇒ Object
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_cache ⇒ Object
192 193 194 195 |
# File 'lib/sequel-cacheable.rb', line 192 def restore_cache delete_cache store_cache end |
#store_cache ⇒ Object
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 |