我想知道是否有任何插件或capistrano recipes可以通过在部署之前或本地构建所有页面缓存的HTML来预热Rails应用程序的页面缓存。
我有一些基本上不怎么变化的静态站点,如果HTML已经写好,而不是需要一个访问者访问网站,它们会运行得更快。
不想自己创建这个(似乎很容易但优先级很低),它是否已经存在?
我想知道是否有任何插件或capistrano recipes可以通过在部署之前或本地构建所有页面缓存的HTML来预热Rails应用程序的页面缓存。
我有一些基本上不怎么变化的静态站点,如果HTML已经写好,而不是需要一个访问者访问网站,它们会运行得更快。
不想自己创建这个(似乎很容易但优先级很低),它是否已经存在?
您可以使用 wget
或另一个程序来爬取网站。实际上,在其手册页面中提到了这种情况作为其用途之一:
This option tells Wget to delete every single file it downloads, after having done so. It is useful for pre-fetching popular pages through a proxy, e.g.:
wget -r -nd --delete-after http://whatever.com/~popular/page/
The -r option is to retrieve recursively, and -nd to not create directories.
我使用一个类似这样的 rake 任务,每晚刷新我的页面缓存站点地图:
require 'action_controller/integration'
ActionController::Base::expire_page("/sitemap.xml")
app = ActionController::Integration::Session.new
app.host = "notexample.com"
app.get("/sitemap.xml")
require 'action_dispatch/testing/integration'
然后用 app = ActionDispatch::Integration::Session.new Rails.application
初始化。 - andialleswget -r --level=5 --no-parent --delete-after \
--wait=2 --waitretry=10 \
--server-response \
--append-output=/tmp/spidering-`date "+%Y%m%d"`.log
'http://whatever.com/~popular/page/'