How to make Rails caches_page survive when deploying capistrano?

Is it possible to configure Rails so that caches created with caches_page can withstand Capistrano deployment? That is, is it possible to configure the cache to be saved in a shared directory, and not in a shared directory?

+4
source share
3 answers

The accepted answer is in order, but it’s better not to copy everything at deployment, but simply to symbolize the cache folder.

Thus, you can create your folder in shared / directory and symbolically bind it to the deployment, for example:

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" 
+4
source

Capistrano is not actually associated with Rails; it is commonly used by the Rails community for deployment. No, you cannot "customize 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 to the new deployment before it is marked 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 do not think that you want to do such a thing for cached pages, because the cache most likely does not synchronize with the release of new code.

+1
source

I found that this is enough for the public / cache directory to be symbolically linked to the shared one:

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

Source: https://habr.com/ru/post/1303501/


All Articles