Module: TinyCache::ActiveRecord::Base::InstanceMethods

Defined in:
lib/tiny_cache/active_record/base.rb

Instance Method Summary collapse

Instance Method Details

#expire_tiny_cacheObject



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_atObject



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_inObject



131
132
133
# File 'lib/tiny_cache/active_record/base.rb', line 131

def tiny_cache_expires_in
  self.class.tiny_cache_options[:expires_in]
end

#tiny_cache_keyObject

缓存的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.extract_options!

  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
  options = args.extract_options!

  self.class.cache_store.fetch self.tiny_cache_method_key(args), options 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_cacheObject



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_cacheObject 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