Pages

Friday, March 04, 2016

Caching Database Results in Rails 4.2.5

If you make the same database calls within any one request, Rails will cache the database result. You don't need to use use ||= to cache the value.
def show
Article.find(params[:id])
Article.find(params[:id])
end

SQL Caching

Query
caching is a Rails feature that caches the result set returned by each
query so that if Rails encounters the same query again for that request,
it will use the cached result set as opposed to running the query
against the database again.