What is the best way to cache an API response in Ruby on Rails?
-
-
Answer:
If you are using ActiveModelSerializer (recommended) then caching is built in. https://github.com/rails-api/active_model_serializers#caching This will cache the entire response in whatever cache store you have setup (e.g. Redis, Memcached). Have a read through the caching guide on Rails: http://guides.rubyonrails.org/caching_with_rails.html
Matt Smith at Quora Visit the source
Other answers
you can cache the hole json response in redis. create then a presenter of a struct that represent the json. add version to the json response, then you can make a cheap get call to the api, and check the version, if is the same, return from redis, if not, to bad, get the response and cache it :) ps: I'm a junior dev
Claudiu Ion
Related Q & A:
- What is the best way to distribute an audio/video feed from a computer to TVs over existing indoor coax cable?Best solution by Audio-Video Production
- What is the best way to clean LEGO bricks?Best solution by bricks.stackexchange.com
- What is the best way to make UI for an Isometric game in Java?Best solution by Game Development
- What is the best way to calculate a date difference?Best solution by Stack Overflow
- What is the best way to count lines in file?Best solution by Stack Overflow
Just Added Q & A:
- How many active mobile subscribers are there in China?Best solution by Quora
- How to find the right vacation?Best solution by bookit.com
- How To Make Your Own Primer?Best solution by thekrazycouponlady.com
- How do you get the domain & range?Best solution by ChaCha
- How do you open pop up blockers?Best solution by Yahoo! Answers
For every problem there is a solution! Proved by Solucija.
-
Got an issue and looking for advice?
-
Ask Solucija to search every corner of the Web for help.
-
Get workable solutions and helpful tips in a moment.
Just ask Solucija about an issue you face and immediately get a list of ready solutions, answers and tips from other Internet users. We always provide the most suitable and complete answer to your question at the top, along with a few good alternatives below.