Module: TinyCache::ActiveRecord::Base::InstanceMethods
- Defined in:
- lib/tiny_cache/active_record/base.rb
Instance Method Summary collapse
- #expire_tiny_cache ⇒ Object
- #refresh_tiny_cache_updated_at ⇒ Object
-
#tiny_cache_key ⇒ Object
缓存的key.
- #tiny_cache_method_expire(*args) ⇒ Object
- #tiny_cache_method_fetch(*args, &block) ⇒ Object
- #tiny_cache_method_key(args) ⇒ Object
- #try_load_from_tiny_cache ⇒ Object
- #write_tiny_cache ⇒ Object (also: #update_tiny_cache)
Instance Method Details
#expire_tiny_cache ⇒ Object
95 96 97 |
# File 'lib/tiny_cache/active_record/base.rb', line 95 def expire_tiny_cache self.class.expire_tiny_cache(self.id) end |
#refresh_tiny_cache_updated_at ⇒ Object
117 118 119 |
# File 'lib/tiny_cache/active_record/base.rb', line 117 def refresh_tiny_cache_updated_at self.updated_at = Time.now end |
#tiny_cache_key ⇒ Object
缓存的key
91 92 93 |
# File 'lib/tiny_cache/active_record/base.rb', line 91 def tiny_cache_key self.class.tiny_cache_key(self.id) end |
#tiny_cache_method_expire(*args) ⇒ Object
107 108 109 110 111 |
# File 'lib/tiny_cache/active_record/base.rb', line 107 def tiny_cache_method_expire *args = args. self.class.cache_store.delete self.tiny_cache_method_key(args) end |
#tiny_cache_method_fetch(*args, &block) ⇒ Object
99 100 101 102 103 104 105 |
# File 'lib/tiny_cache/active_record/base.rb', line 99 def tiny_cache_method_fetch *args, &block = args. self.class.cache_store.fetch self.tiny_cache_method_key(args), do block.call end end |
#tiny_cache_method_key(args) ⇒ Object
113 114 115 |
# File 'lib/tiny_cache/active_record/base.rb', line 113 def tiny_cache_method_key args "#{self.tiny_cache_key}/method_fetch/#{args.join('/')}" end |
#try_load_from_tiny_cache ⇒ Object
86 87 88 |
# File 'lib/tiny_cache/active_record/base.rb', line 86 def try_load_from_tiny_cache self.class.read_tiny_cache(self.id) || self end |
#write_tiny_cache ⇒ Object Also known as: update_tiny_cache
121 122 123 124 125 126 127 |
# File 'lib/tiny_cache/active_record/base.rb', line 121 def write_tiny_cache if self.class.tiny_cache_enabled? ::TinyCache.cache_store.write( self.tiny_cache_key, RecordMarshal.dump(self), :expires_in => self.class.[:expires_in] ) end end |