The built-in page caching has been extracted to a separate gem in Rails 4 and here is a guide how to use it. First we need to add the gem to our Gemfile: Than in the application controller we need to specify the folder to store our cache files: Let's say we have an article controller and we want to cache the index and the show action: Now if we have the `config.action_controller.perform_caching` set to `true` Rails will generated the HTML output of the pages in the cache folder. One more thing we need to do is to tell the webserver to use the cached version if there is one so the request won't even hit our app. With nginx we can achieve this with a configuration like this: Now we managed to serve the cached version of our pages but we need a way to flush the cache when it needs. To achieve this we will user a Sweeper. In Rails 4 the cache sweepers are also moved to a separate gem with the observers so we need to add the it to the Gemfile: Than we need to create a file in the app/sweepers folder called article_sweeper.rb and call the `expire_page` method with a reference to the page we want to flush the cache for. Let's say we use a user friendly url field for the articles and the cache files will be named after that field. In this case to expire those we will need to pass the raw url string to the method: That's all, we achieved to setup the page caching for our Rails 4 app. ## Resources actionpack-page_caching rails-observers
I run an indie startup providing vulnerability scanning for your Ruby on Rails app.
It is free to use at the moment, and I am grateful for any feedback about it.