Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 371
Ashish Bista Avatar asked Jun 14 '13 14:06

Ashish Bista


1 Answers

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

like image 155
Wizard of Ogz Avatar answered Oct 24 '22 23:10

Wizard of Ogz