When you retrieve data using api, is it better to store this data in another database or is it better to receive data when you need it?

I use the TMDB api to get information, such as movie titles and years of release, but I wonder if I need to create an additional database to store all this information locally, instead of continuing to use the api to get the information? For example, whether to create a movie model and call:

film.title

and thereby access the local database with the header stored in it or call:

Tmdb::Movie.detail(550).title

and thereby make another api call?

+4
source share
3 answers

Rails-, , - . . , . . " Ruby on Rails" :

. Rails .

Rails.cache.fetch. , . , . , .

, :

class TmdbService
  def self.movie_details(id)
    Rails.cache.fetch("tmdb.movie.details.#{id}", expires_in: 4.hours) do
      Tmdb::Movie.detail id
    end
end

Rails memcached , . , , - , , .

+2

. , API, , . , , , API .

, , , , .

- , .

- , . , .

0

, API. , , API, , . .

API API.

: ? ? API ? API ( )?

0

Source: https://habr.com/ru/post/1654119/


All Articles