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

发布于 2024-08-24 07:17:29 字数 91 浏览 10 评论 0原文

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

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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

马蹄踏│碎落叶 2024-08-31 07:17:29

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

这样,您可以在共享/目录中创建文件夹并在部署时对其进行符号链接,如下所示:

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"

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"
娇女薄笑 2024-08-31 07:17:29

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"

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

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.

煮茶煮酒煮时光 2024-08-31 07:17:29

我发现这足以将 public/cache 目录符号链接到共享下:

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

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

set :shared_children, shared_children + ["public/cache"]
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文