Module: Samurai::CacheableByToken::ClassExtensions

Defined in:
lib/samurai/cacheable_by_token.rb

Instance Method Summary collapse

Instance Method Details

#find(*arguments) ⇒ Object

Override the ActiveResource ‘find` method to query the cache before hitting the provider.



23
24
25
26
27
28
29
30
31
32
33
# File 'lib/samurai/cacheable_by_token.rb', line 23

def find(*arguments)
  token = arguments.first
  if token.is_a?(String) && self.cache[token]
    # cache hit
    self.cache[token]
  else
    # cache miss
    obj = super(*arguments)
    self.cache[obj.id] = obj
  end
end