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_expires_in ⇒ 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
105 106 107 |
# File 'lib/tiny_cache/active_record/base.rb', line 105 def expire_tiny_cache self.class.expire_tiny_cache(self.id) end |
#refresh_tiny_cache_updated_at ⇒ Object
127 128 129 |
# File 'lib/tiny_cache/active_record/base.rb', line 127 def refresh_tiny_cache_updated_at self.updated_at = Time.now end |
#tiny_cache_expires_in ⇒ Object
131 132 133 |
# File 'lib/tiny_cache/active_record/base.rb', line 131 def tiny_cache_expires_in self.class.[:expires_in] end |
#tiny_cache_key ⇒ Object
缓存的key
101 102 103 |
# File 'lib/tiny_cache/active_record/base.rb', line 101 def tiny_cache_key self.class.tiny_cache_key(self.id) end |
#tiny_cache_method_expire(*args) ⇒ Object
117 118 119 120 121 |
# File 'lib/tiny_cache/active_record/base.rb', line 117 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
109 110 111 112 113 114 115 |
# File 'lib/tiny_cache/active_record/base.rb', line 109 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
123 124 125 |
# File 'lib/tiny_cache/active_record/base.rb', line 123 def tiny_cache_method_key args "#{self.tiny_cache_key}/method_fetch/#{args.join('/')}" end |
#try_load_from_tiny_cache ⇒ Object
96 97 98 |
# File 'lib/tiny_cache/active_record/base.rb', line 96 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
135 136 137 138 139 140 141 |
# File 'lib/tiny_cache/active_record/base.rb', line 135 def write_tiny_cache if self.class.tiny_cache_enabled? ::TinyCache.cache_store.write( self.tiny_cache_key, RecordMarshal.dump(self), :expires_in => tiny_cache_expires_in ) end end |