How to make Rails caches_page survive a capistrano deploy?

actioncontroller, caching, capistrano, ruby, ruby-on-rails

Solution

The accepted answer is OK, but it's generally better not to copy everything upon the deployment, but just symlink the cache folder.

This way, you can create your folder in shared/ directory and symlink it upon deployment like:

namespace :deploy do
   desc "Link cache folder to the new release"
   task :link_cache_folder, :roles => :app, :on_error => :continue do
     run "ln -s #{shared_path}/cache #{latest_release}/public/cache"  
   end
end

before "deploy:symlink", "deploy:link_cache_folder"

Problem

Is it possible to configure Rails so caches created with caches_page survive a Capistrano deploy? Ie, can I configure the cache to be saved into a shared directory rather than in the public directory?

Original source