如何使 Rails caches_page 在 capistrano 部署中幸存?
是否可以配置 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
接受的答案是好的,但通常最好不要在部署时复制所有内容,而只是符号链接缓存文件夹。
这样,您可以在共享/目录中创建文件夹并在部署时对其进行符号链接,如下所示:
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:
Capistrano 与 Rails 并不真正相关,它只是 Rails 社区常用来进行部署。所以不,你不能“配置Rails”来做你想做的事。您可以做的就是向 Capfile 添加一个任务,该任务运行 shell 命令以将缓存复制到新部署中,然后再将其符号链接为“当前”。
但我真的不认为你会想对缓存页面做这样的事情,因为缓存可能与新代码的输出不同步。
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'.
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.
我发现这足以将 public/cache 目录符号链接到共享下:
I found this was sufficient to have the public/cache directory symlinked under shared: