Class: CachedRecord::Base

Inherits:
ActiveRecord::Base
  • Object
show all
Defined in:
lib/cached_record/base.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.cache_storeObject



17
18
19
# File 'lib/cached_record/base.rb', line 17

def cache_store
  @cache_store ||= ::CachedRecord.cache_store
end

.find_one(id, options) ⇒ Object



6
7
8
9
10
11
12
13
14
15
# File 'lib/cached_record/base.rb', line 6

def find_one(id,options)
  return super unless options.empty?
  key = "#{self.table_name}::#{id}"
  if value = cache_store.get(key)
  else
    value = super
    cache_store.set(key,value)
  end
  return value
end

Instance Method Details

#save(run_validations = true) ⇒ Object



23
24
25
26
# File 'lib/cached_record/base.rb', line 23

def save(run_validations = true)
  self.class.cache_store.set "#{self.class.table_name}::#{id}", nil
  super
end