Answer the question
In order to leave comments, you need to log in
How to cache raw SQL results in Rails?
There is a certain model MyModel , which describes a fairly large amount of data. For this model, a regular pure SQL query was written, which could not be written in the ActiveRecord version.
There was a need to use the cache in order not to constantly execute this request, but to store the values in the cache for some time.
Let's say there is a code:
sql_query = " ... " #большущий запрос
items = Rails.cache.fetch("some_key", :expires_in => 1.day) do
MyModel.connection.select_rows(sql_query)
end
puts items
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question