Performance: Why caching improves response times
HIGH IMPACT
Caching reduces server processing time and network delays, speeding up page load and interaction response.
def show @post = Rails.cache.fetch("post_#{params[:id]}") { Post.find(params[:id]) } render json: @post end
def show
@post = Post.find(params[:id])
render json: @post
end| Pattern | DOM Operations | Reflows | Paint Cost | Verdict |
|---|---|---|---|---|
| No caching, fetch from DB every time | N/A (server-side) | N/A | N/A | [X] Bad |
| Cache data with Rails.cache.fetch | N/A (server-side) | N/A | N/A | [OK] Good |