Caching Rendered PDFs in Rails with Active Storage - Harisankar P S | Ruby on Rails Developer
28-Jul-2025 42
As I was working on easyclientlog.com, building its invoice system that allows freelancers/consultants to generates PDFs. Working with PDF generating is that, its takes time and CPU cycles. But most of the time the pdf only needs to be generated once, and the content seldom changes. So rendering the same thing over and over just didn’t feel right. So I used a simple trick that I’ve followed in many of my prior Rails apps: upload the PDF on first render, store it using Active Storage, and reuse that file on the next access.
The Idea: Cache on First Render
When the PDF is generated the first time, we attach it to the record using Active Storage. This could be an invoice, report, or any other object. The next time we need to show or download the PDF, we skip the rendering step and simply serve the uploaded file.
This avoids unnecessary rendering and speeds up response times, especially for large documents or when generating in bulk.
Caching Rendered PDFs in Rails with Active Storage - Harisankar P S | Ruby on Rails Developer #ruby #rubydeveloper #rubyonrails #Caching #Rendered #Rails #Active #Storage #Harisankar #Rails #Developer #active #developer https://rubyonrails.ba/link/caching-rendered-pdfs-in-rails-with-active-storage-harisankar-p-s-ruby-on-rails-developer