是否有可能无需访问网站告诉rails一起执行application.html.erb页面中所有文件的缓存?
我的页面中有以下代码:
<%= stylesheet_link_tag'reset','forms','layout','common','pages',:cache => '_cached'%>
当在生产模式下首次加载网站时,这会将所有内容组合成一个_cached.css文件。但是,我想在网站初始化后重新生成文件。
所以步骤将是
关于如何做到这一点的任何想法?可以作为rake命令下来吗?
答案 0 :(得分:1)
设置一个rake任务,一旦加载网站就访问网站文件,这就可以了。
namespace :assets do
desc "Removing existing cached files"
task :clear => :environment do
FileUtils.rm(Dir['public/javascripts/_cached.js'])
FileUtils.rm(Dir['public/javascripts/_ie6.js'])
FileUtils.rm(Dir['public/stylesheets/_cached.css'])
end
desc "Recreate the javascripts/stylesheets cache."
task :generate => [:environment, :clear] do
puts "Recreate the javascripts/stylesheets cache"
ActionController::Base.perform_caching = true
app = ActionController::Integration::Session.new(ActionController::Dispatcher.new)
app.get '/'
end
end
答案 1 :(得分:0)
将它放在lib / tasks /文件中:
namespace :tmp do
namespace :assets do
desc "Clears javascripts/cache and stylesheets/cache"
task :clear => :environment do
FileUtils.rm(Dir['public/javascripts/cache.js'])
FileUtils.rm(Dir['public/stylesheets/cache.css'])
end
end
end
然后将其作为部署脚本或capistrano配方的一部分进行调用:
namespace :deploy do
task :start do ; end
task :stop do ; end
task :restart, :roles => :app, :except => { :no_release => true } do
run "cd #{current_path} && /usr/bin/env rake tmp:assets:clear RAILS_ENV=#{stage}"
run "#{try_sudo} touch #{File.join(current_path,'tmp','restart.txt')}"
end
end