Module: SimpleModelCache::ClassMethods

Defined in:
lib/simple_model_cache.rb

Instance Method Summary collapse

Instance Method Details

#cache_fields(*fields) ⇒ Object



16
17
18
19
20
# File 'lib/simple_model_cache.rb', line 16

def cache_fields(*fields)
  @cached_fields = [:id]
  @cached_fields += fields
  define_finder_methods
end

#find(*id_params) ⇒ Object



22
23
24
25
26
27
28
29
30
# File 'lib/simple_model_cache.rb', line 22

def find(*id_params)
  ids = id_params.compact
  from_cache = ids.count == 1 ? find_one(ids.first) : find_many(ids) 
  if from_cache.blank?
    super
  else
    from_cache
  end
end