all posts

Quickly clear the Rails cache in development

Tipsy tip

Adrian Marin

68 words 1 min read

Use this quick helping before_action to quickly bust the cache in development.

You need to add this snippet in your application_controller.rb and then append the clear_cache=1 param to any URL you visit.

# app/controllers/application_controller.rb

# Append this param to bust the cache in development 🙌
# https://localhost:3000?clear_cache=true
before_action :clear_cache_if_requested if Rails.env.development?

def clear_cache_if_requested
  Rails.cache.clear if params[:clear_cache].present?
end

Join the newsletter

Rails guides, Avo releases, and useful lessons from building the admin layer.

No noise. Unsubscribe whenever you like. Read our privacy policy.