A website we are developing takes quite some time to load a product the first time. I am assuming at this time Magento is caching all the images that are being presented to the user (6 in total, starting at a pretty large resolution 2400 x 1200).
My assumption is based in the fact that the next time I load the product after clearing my local cache, the product and images load much much faster.
The simple solution to me is to visit each product one time, this is not ideal in the case that we have to flush the image cache for one reason or another.
I am sure I can write a script that will pre-cache each开发者_运维问答 image, but I am curious if there is a built in mechanism for something like this?
Since the page remains fast after clearing the local cache you must be concerned about the server cache. The answer here is resized images are already saved separately to the normal cache, in media/catalog/product/cache
as opposed to var/cache/
. If you look in System > Cache Management you will see there is a separate button for clearing just those images, so unless you really need to, avoiding clicking that button.
I had a similar need on pre-caching, or at least rebuilding the cache after a purge. There is nothing built in to do this so I wrote a quick and dirty script to parse the sitemap xml file and crawl the site from the command line... thus causing magento to generate the image cache for all the pages.
The script assumes you have a sitemap.xml in the same directory. It's meant to be ran from the command line outside of the web root.
<?php
ini_set("memory_limit","500M");
ini_set('max_execution_time', 600);
$d = file_get_contents('sitemap.xml');
$data = @new SimpleXMLElement($d);
$cnt = count($data);
$i = 1;
foreach ($data as $row) {
$url = $row->loc;
echo "$i of $cnt : $url \n";
$buffer = file_get_contents($url);
$buffer = '';
flush();
$i++;
}
精彩评论