Last updated March 12, 2013. Created by Greg Sims on May 14, 2012.
Edited by John Bickar. Log in to edit this page.
Drupal creates pages and serves them to clients. The completed pages are also stored in the cache_page table of the database -- referred to as the Page Cache. This function is enabled on page admin/settings/performance. The nominal settings for the Page Cache section is:
- Caching Mode: Normal
- Minimum Cache Lifetime: None
- Page Compression: Enabled
With these settings the Page Cache will be emptied every time cron runs. Please take this into consideration when you set the number of times cron runs each day. The cron job of our production website runs once per day just after midnight when traffic on the website is low.
The problem with this setup is the Page Cache is empty after cron runs. This means the first time a user accesses a page the completed page will not be in the Page Cache and the access will be slow. We can solve this problem by loading all the webpages of the site when cron completes (known as "cache warming"). You can do this by creating a script that runs the standard cron job followed by some code that loads each page in sitemap.xml into the Page Cache:
#!/bin/bash
#
# this is the standard Drupal cron invocation that runs from cron
# this will flush the Page Cache when Minimum Cache Lifetime set to <none>
#
wget -O - -q -t 1 http://www.example.com/cron.php
#
# use the sitemap and reload the Page Cache by accessing each page once
#
wget --quiet http://www.example.com/sitemap.xml --output-document - | egrep -o "http://www.example.com[^<]+" | wget -q --delete-after -i -O -
You need to change www.example.com in the code above to the domain of your website. Run this script from cron instead of the standard cron invocation. Now the webpages of your website in sitemap.xml are loaded into your Page Cache waiting for the first user access. This first user access will now be served from the Page Cache -- much faster.
See also:
Comments
wget for windows
I have both commands installed on my windows however egrep -o command was not recognized. Are there some commands variation among versions?
is there any steo by step
is there any steo by step tutorial of how to add this code, and where to past it?