Вот почитай эту статью Кеширование блоков с sql-запросами для slaed cms.
Ну а тут готовое решение
Написал на скорую руку . Есть ньансы но думаю разберешься
Найти код в modules/news/index.php
<br />
//старый код<br />
if ($confn['assoc']) {<br />
if ($associated[strlen($associated)-1] == "-") $associated = substr($associated, 0, -1);<br />
$asso = str_replace("-", ",", $associated);<br />
$limit = intval($confn['asocnum']);<br />
list($count) = $db->sql_fetchrow($db->sql_query("SELECT Count(sid) FROM ".$prefix."_news WHERE catid IN (".$asso.") AND sid!='".$id."' AND time<=now() AND status!='0'"));<br />
if ($count >= $limit) {<br />
$random = mt_rand(0, $count - $limit);<br />
$result = $db->sql_query("SELECT sid, title, time FROM ".$prefix."_news WHERE catid IN (".$asso.") AND sid!='".$id."' AND time<=now() AND status!='0' ORDER BY time DESC LIMIT ".$random.", ".$limit);<br />
$cont .= tpl_eval("open");<br />
$cont .= "<h2>"._ASSTORY."</h2>"<br />
."<table width=\"100%\" border=\"0\" cellpadding=\"3\" cellspacing=\"0\" class=\"hover\">";<br />
while(list($s_sid, $title, $time) = $db->sql_fetchrow($result)) {<br />
$cont .= "<tr><td><a href=\"index.php?name=".$conf['name']."&op=view&id=".$s_sid."\" title=\"".$title."\"><img src=\"".img_find("all/news.png")."\" border=\"0\"></a></td><td width=\"98%\"><a href=\"index.php?name=".$conf['name']."&op=view&id=".$s_sid."\" title=\"".$title."\">".$title."</a></td></tr>";<br />
}<br />
$cont .= "</table>";<br />
$cont .= tpl_eval("close");<br />
}<br />
}<br />
заменить на
<br />
//новый код будет создавать файл кеша с ид данной новости<br />
if ($confn['assoc']) {<br />
//проверяем если кеш есть то берем из кеша<br />
if(file_exists("config/cache/newsrelated".$id.".tmp")){<br />
$cont .= file_get_contents("config/cache/newsrelated".$id.".tmp");<br />
}<br />
//если нет то создаем фал кеша с ид данной новости<br />
else{<br />
<br />
if ($associated[strlen($associated)-1] == "-") $associated = substr($associated, 0, -1);<br />
$asso = str_replace("-", ",", $associated);<br />
$limit = intval($confn['asocnum']);<br />
list($count) = $db->sql_fetchrow($db->sql_query("SELECT Count(sid) FROM ".$prefix."_news WHERE catid IN (".$asso.") AND sid!='".$id."' AND time<=now() AND status!='0'"));<br />
if ($count >= $limit) {<br />
$random = mt_rand(0, $count - $limit);<br />
$result = $db->sql_query("SELECT sid, title, time FROM ".$prefix."_news WHERE catid IN (".$asso.") AND sid!='".$id."' AND time<=now() AND status!='0' ORDER BY time DESC LIMIT ".$random.", ".$limit);<br />
$cont .= tpl_eval("open");<br />
$cont .= "<h2>"._ASSTORY."</h2>"<br />
."<table width=\"100%\" border=\"0\" cellpadding=\"3\" cellspacing=\"0\" class=\"hover\">";<br />
while(list($s_sid, $title, $time) = $db->sql_fetchrow($result)) {<br />
$cont .= "<tr><td><a href=\"index.php?name=".$conf['name']."&op=view&id=".$s_sid."\" title=\"".$title."\"><img src=\"".img_find("all/news.png")."\" border=\"0\"></a></td><td width=\"98%\"><a href=\"index.php?name=".$conf['name']."&op=view&id=".$s_sid."\" title=\"".$title."\">".$title."</a></td></tr>";<br />
}<br />
$cont .= "</table>";<br />
$cont .= tpl_eval("close");<br />
}<br />
//записываем кеш<br />
$fp = fopen("config/cache/newsrelated".$id.".tmp", "wb");fwrite($fp,$cont);fclose($fp);<br />
<br />
<br />
}<br />
<br />
<br />
<br />
<br />
} <br />
<br />
В function/function.php добавить функцию
/* удалнение кеша*/<br />
function clear_cache($cache_area = false,$system="") {<br />
$adsystem = ($system) ? '/system' : "";<br />
$fdir = opendir('config/cache'.$adsystem.'' );<br />
<br />
while ( $file = readdir( $fdir ) ) {<br />
if( $file != '.' and $file != '..' and $file != '.htaccess' and $file != 'system' ) {<br />
<br />
if( $cache_area ) {<br />
<br />
if( strpos( $file, $cache_area ) !== false ) @unlink( 'config/cache/'.$adsystem.'' . $file );<br />
<br />
} else {<br />
<br />
@unlink( 'config/cache/'.$adsystem.'' . $file );<br />
<br />
}<br />
}<br />
}<br />
}
В файле modules/news/admin/index.php в функции function news() после строки
echo $cont;
Вставить
<br />
//Теперь при заходе в админку буде очищаться весь кеш.<br />
clear_cache();<br />
<br />