Module: Sparkle::Refreshable::ClassMethods

Defined in:
lib/sparkle/refreshable.rb

Instance Method Summary collapse

Instance Method Details

#sparkle_fetch(*args) ⇒ Object



24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/sparkle/refreshable.rb', line 24

def sparkle_fetch(*args)
  key = _sparkle_cache_key(*args)
  if object = Rails.cache.read(key)
    begin
      object._sparkle_cached_ = true
    rescue TypeError => e
      object = object.dup
      object._sparkle_cached_ = true
    end
  else
    object = new(*args)
    object.send object.class._sparkle_cache_refresh_method
    object._sparkle_cached_ = false
    object._sparkle_cache_key_ = key
    Rails.cache.write(key, object)
  end
  object
end

#sparkle_refresh_method(method_name) ⇒ Object



20
21
22
# File 'lib/sparkle/refreshable.rb', line 20

def sparkle_refresh_method method_name
  self._sparkle_cache_refresh_method = method_name.to_sym
end