Imagecacheを介して実行されるノードごとのimagefieldがあります。 imagecacheはオンデマンドでキャッシュするため、キャッシュファイル/バリエーションは、最初にリクエストされるまで作成されません。したがって、一連のイメージを更新したり、再デプロイしたり、キャッシュ全体をブローしたりする場合、そのファイルを処理するのは最初のビジター次第です。
そのユーザーの読み込み時間を節約し、キャッシュ全体を手動で再構築するにはどうすればよいですか?
これが最後に出てきたときに、jqueryですべてのノードリンクをプログラムでロードしました...
完璧なDrushプラグインのように思われます...おそらくそれを書くことを検討する必要がありますが、他の誰かがこれに対する解決策を持っているかどうか知りたいです。
カスタムモジュールを作成し、次に hook_cron() を使用してイメージケージを再構築できます。
私は、サーバーサイドでそれを行う方法を考えようとして、最後の1時間を費やしたばかりで、私はそれを解読したと思います。
_/**
* Implements hook_cron().
*/
function rebuildimagecache_cron() {
global $base_url;
// get published nodes
$result = db_query('SELECT nid FROM {node} WHERE status = 1');
while ($nodes = db_fetch_array($result)) {
$node = node_load($nodes['nid']);
$node_type = $node->type;
// get cck fields for the current nodes node_type
$fields = content_fields(NULL, $node_type);
foreach ($fields as $key => $value) {
// only deal with file fields that use the image widegt tyoe
if ($value['type'] == 'filefield' && $value['widget']['type'] == 'imagefield_widget') {
$preset_tokens = explode('_', $value['display_settings']['full']['format']);
$imagecache_preset = $preset_tokens[0];
$field_name = $value['field_name'];
// iterate over each field instance
foreach ($node->$field_name as $field_instance) {
$filepath = $field_instance['filepath'];
$cachedpath = imagecache_create_path($imagecache_preset, $filepath);
file_get_contents($base_url . base_path() . $cachedpath);
}
}
}
}
}
_
使い方:
私はそれをテストしましたが、Drupal 6でうまく機能しました。Drupal 7バージョンは、基になるFile APIの変更により、少しトリッキーになります。
カスタムモジュールを作成してこの関数を貼り付ける必要があります。フック名もrebuildimagecache
からカスタムモジュールの名前に変更してください。
私はhook_cron()
を使用してcronの実行時に実行されるようにしましたが、drush
コマンドを使用して手動で実行することもできます。
ローテクなアプローチ...
ああ、管理者だけがそのビューに対する権限を持っていることを確認してください。
パフォーマンスに関する1つのヒント:画像キャッシュをトリガーするために画像コンテンツ全体をロードする必要はありません。ヘッダーをリクエストすることもできます。したがって、この行:
file_get_contents($base_url . base_path() . $cachedpath);
なる
get_headers($base_url . base_path() . $cachedpath);
私の解決策:
function example_cron() {
$result = db_query('SELECT fid, uri FROM {file_managed} WHERE filemime like :mime AND status = :status', array('mime' => 'image/%', 'status' => FILE_STATUS_PERMANENT));
$queue = DrupalQueue::get('generate_image_styles');
foreach ($result as $img_info) {
foreach(image_styles() as $style) {
$derivative_uri = image_style_path($style['name'], $img_info->uri);
if (file_exists($derivative_uri)) continue; // skip existing files
$data = (object) array(
'style' => $style,
'img_info' => $img_info,
'derivative_uri' => $derivative_uri
);
$queue->createItem($data);
}
}
}
function example_cron_queue_info(){
$queues['generate_image_styles'] = array(
'worker callback' => '_example_generate_image_styles',
'time' => 30
);
return $queues;
}
function _example_generate_image_styles($data){
if (!file_exists($data->derivative_uri)) {
image_style_create_derivative($data->style, $data->img_info->uri, $data->derivative_uri);
}
}
この種のことを機能させようとする試みがありました、 Imagecache Batch を参照してください。しかし、これらの機能の開発がどこにあるのかわかりません。 D6とD7のどちらを扱っているかは明言していませんが、6.x-2.x-devのアクションとルールを調べて、どこにあるのかを確認します。
これは実行され、うまく機能しました。ここを参照してください https://drupal.org/node/587086
スレッドの最後で完全なファイルパッチを試してください。標準のように、ルートではなく/sites/all/modules/imagecache/imagecache.drush.inc
内で実行してください。