Usamos cookies para medir audiência e melhorar sua experiência. Você pode aceitar ou recusar a qualquer momento. Veja sobre o iMasters.
Ola pessoal, eu tenho uma função muito útil aqui pra quem tem problemas de overload no server relacionado a consultas aos banco de dados etc, mas antes deste topico ser passado para o laboratório de scripts, queria uma ajuda para resolver um problema nele.
O código este com um problema: Se eu quero cachear somente determinada parte de um codigo, posso faze-lo, mas ele ignora a parte debaixo do codigo.
Por exemplo: Suponhamos que queira cachear parte da tabela abaixo:
<?
//funçoes
function cache_start($age,$file_name)
{
global $cache_file;
$cache_file = "/usr/local/apache/htdocs/cache/". $file_name . ".dat";
$cachetime = 600;
// Serve from the cache if it is younger than $cachetime
if (file_exists($cache_file) && (time() - $cachetime
< filemtime($cache_file)))
{
include($cache_file);
exit;
}
// cache empty, or too old
ob_start();
}
function cache_end($file_name) $cache_file = "/usr/local/apache/htdocs/cache/". $file_name . ".dat";
$fp = fopen($cache_file, 'w');
// save the contents of output buffer to the file
fwrite($fp, ob_get_contents());
// close the file
fclose($fp);
// Send the output to the browser
ob_end_flush();
}
?><html xmlns="[http://www.w3.org/1999/xhtml">](http://www.w3.org/1999/xhtml)
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
</head>
<body>
<table width="80%" border="0">
<tr>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
</tr>$cache_name = "tabela_tr";
cache_start(500,$cache_name);
?>
<tr>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
</tr>cache_end($cache_name);
?>
<tr>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
</tr>
<tr>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
</tr>
</table>
</body>
</html>
o cache so retorna isso:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="[http://www.w3.org/1999/xhtml">](http://www.w3.org/1999/xhtml)
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
</head>
<body>
<table width="80%" border="0">
<tr>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
</tr>
<tr>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
</tr>Acho que o problema esta nesta parte do codigo(o exit;):
include($cache_file);
exit;
Mas se eu tiro o "exit;" o cache nao funciona direito
Alguem sabe como posso resolver isto ou tenha alguma função semelhante que funcione melhor?
Desde ja agradeço
Carregando comentários...