Ashish Bista
Ashish Bista

Reputation: 4693

Rails - Caching external HTTP calls

My Rails app has to make a massive amount of external http calls. Sometimes, redundant http calls to handle a request. So, I'm looking for a way to cache external http calls. The way should use memory to keep cached data. Please help.

Upvotes: 5

Views: 1976

Answers (1)

Wizard of Ogz
Wizard of Ogz

Reputation: 12643

It seems like you could just use Rails caching to accomplish this, though I haven't actually tested it.

results = Rails.cache.fetch(cache_key) do  # You could use a unique URL as part of the cache key
  # HTTP request
  # Return results from processing the response
end

More about Rails caching http://guides.rubyonrails.org/caching_with_rails.html

Upvotes: 9

Related Questions