Module: Sequel::Plugins::QueryCache::InstanceMethods
- Defined in:
- lib/sequel-query-cache/instance_methods.rb
Instance Attribute Summary collapse
-
#source_dataset ⇒ Object
For the purpose of caching, it’s helpful to have the dataset that is actually responsible for creating the model instance since it’s likely that if the instance is updated you’ll want the dataset related to it to be cleaned up.
Instance Method Summary collapse
- #after_save ⇒ Object
- #before_save ⇒ Object
- #cache!(opts = {}) ⇒ Object
- #cache_key ⇒ Object
- #to_msgpack(io = nil) ⇒ Object
- #uncache! ⇒ Object
Instance Attribute Details
#source_dataset ⇒ Object
For the purpose of caching, it’s helpful to have the dataset that is actually responsible for creating the model instance since it’s likely that if the instance is updated you’ll want the dataset related to it to be cleaned up. See #recache_source_dataset! for further information.
10 11 12 |
# File 'lib/sequel-query-cache/instance_methods.rb', line 10 def source_dataset @source_dataset end |
Instance Method Details
#after_save ⇒ Object
19 20 21 22 23 |
# File 'lib/sequel-query-cache/instance_methods.rb', line 19 def after_save super recache_source_dataset! cache! end |
#before_save ⇒ Object
12 13 14 15 16 17 |
# File 'lib/sequel-query-cache/instance_methods.rb', line 12 def before_save # Since the cache will be updated after the save is complete there's no # reason to have it deleted by the update process. this.cache_clear_on_update = false super end |
#cache!(opts = {}) ⇒ Object
29 30 31 32 |
# File 'lib/sequel-query-cache/instance_methods.rb', line 29 def cache!(opts={}) this.cache_set([self], opts) if this.is_cacheable? self end |
#cache_key ⇒ Object
25 26 27 |
# File 'lib/sequel-query-cache/instance_methods.rb', line 25 def cache_key this.cache_key end |
#to_msgpack(io = nil) ⇒ Object
40 41 42 |
# File 'lib/sequel-query-cache/instance_methods.rb', line 40 def to_msgpack(io=nil) values.to_msgpack(io) end |
#uncache! ⇒ Object
34 35 36 37 38 |
# File 'lib/sequel-query-cache/instance_methods.rb', line 34 def uncache! this.cache_del if this.is_cacheable? source_dataset.cache_del if source_dataset_cache? self end |