繁体   English   中英

如何使Rails caches_page在capistrano部署中幸存?

[英]How to make Rails caches_page survive a capistrano deploy?

是否可以配置Rails,因此使用caches_page创建的缓存可以在Capistrano部署中生存? 即,我可以将缓存配置为保存到共享目录而不是公共目录中吗?

接受的答案是可以的,但通常最好不要在部署时复制所有内容,而只是将缓存文件夹符号链接。

这样,您可以在shared / directory中创建文件夹,并在部署时对其进行符号链接,如:

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并不真正与Rails相关,它只是Rails社区常用于部署。 所以不,你不能“配置Rails”来做你想要的。 您可以做的是向Capfile中添加一个任务,该任务运行shell命令,在将符号链接为“当前”之前将缓存复制到新部署中。

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"

但我真的不认为你想为缓存页面做这样的事情,因为缓存很可能与新代码的输出不同步。

我发现这足以让public / cache目录符号链接在shared下:

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM