开发者

How to make Rails caches_page survive a capistrano deploy?

开发者 https://www.devze.com 2022-12-22 12:50 出处:网络
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 pu

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?


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"


Capistrano isn't really Rails related, it's just commonly used by the Rails community for deployment. So no, you can't "configure Rails" to do what you want. What you can do is add a task to your Capfile that runs shell commands to copy the cache into your new deployment before it is symlinked as 'current'.

namespace :deploy do
   desc "Copy cache to the new release"
   task :cache_copy, :roles => :app, :on_error => :continue do
     on_rollback {
       run "rm -rf #{latest_release}/public/cache"
     }

     run "cp -a #{current_path}/public/cache #{latest_release}/public"  
   end
end

before "deploy:symlink", "deploy:cache_copy"

But I really don't think you'd want to do such a thing for cached pages because the cache will likely be out of sync with the new code's output.


I found this was sufficient to have the public/cache directory symlinked under shared:

set :shared_children, shared_children + ["public/cache"]
0

精彩评论

暂无评论...
验证码 换一张
取 消