0
0
Ruby on Railsframework~3 mins

Why Page and action caching in Ruby on Rails? - Purpose & Use Cases

Choose your learning style9 modes available
The Big Idea

Discover how saving pages can make your website lightning fast without extra work!

The Scenario

Imagine your website gets many visitors, and each time they click a page, your server runs the same code to build that page from scratch.

This makes users wait longer and your server work harder.

The Problem

Manually rebuilding pages every time is slow and wastes resources.

It can cause delays, especially when many people visit at once.

Also, writing code to save and reuse pages yourself is tricky and easy to get wrong.

The Solution

Page and action caching automatically saves the full page or action result after the first request.

Next visitors get the saved version instantly without running the code again.

This makes your site faster and reduces server load.

Before vs After
Before
def show
  @post = Post.find(params[:id])
  render :show
end
After
caches_page :show

def show
  @post = Post.find(params[:id])
end
What It Enables

It enables your website to serve pages instantly to many users, improving speed and handling more visitors smoothly.

Real Life Example

A news website uses page caching so when thousands read the same article, the server quickly sends the saved page instead of rebuilding it each time.

Key Takeaways

Manual page building is slow and resource-heavy.

Page and action caching store results to serve faster next time.

This improves user experience and server efficiency.