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.



17
18
19
20
21
22
23
24
25
26
27
# File 'lib/samurai/cacheable_by_token.rb', line 17

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