Author |
Message |
dean
Worker


Joined: Apr 14, 2004
Posts: 193
|
Posted:
Fri Jul 22, 2005 1:23 pm |
|
Yesterday I finally figured out how to use cache lite and also found a spot where not to, ie the user info block. I found it impossible to log in or out with that block cached. I thought that caching the block would really speed up the site because of all of the calls made to the database.
Is there any reason why block modules cannot be cached?
Also, one block in particular delivered a tstring error when the caching script was added to it. Is it possible that some blocks cannot be cached or is this a block that needs some modification to work? I'm speaking specifically about a block at my site at Only registered users can see links on this board! Get registered or login!, lower left that displays a list of the last advertisements placed in the database (zclassified module). |
|
|
|
 |
Raven
Site Admin/Owner

Joined: Aug 27, 2002
Posts: 17088
|
Posted:
Fri Jul 22, 2005 3:42 pm |
|
Blocks are the only thing that you will want to cahce, due to the way nuke builds blocks vs. modules. Modules can also be cached, but they can take alot of rewriting to do so. The rule of thumb is that you want to cache blocks that you can estimate the refresh time and especially those blocks that take time to build. So, since your userinfo block is mostly constantly changing, you would not want to cache it. Although you could remove the Login piece and use a more singular, stand-alone login block. Then, you would alleviate that issue. However, I still don't recommend caching that. I cache the following. The numeric value is for the number of seconds before refreshing. If I update before then, I just use my CL Admin module to refresh the block.
Code:Donate o Meter 300
Partners 86400
Proverb of the Day 86400
Recommended Sites 86400
Subscription Module 3600
Verse of the Day 86400
|
|
|
|
|
 |
dean

|
Posted:
Fri Jul 22, 2005 7:13 pm |
|
One of the blocks I'm using delivers this error when the cache script is applied to it: Quote: | Parse error: parse error, unexpected T_VARIABLE in /home/alaskand/public_html/main/blocks/block-ZClassified.php on line 65
|
Line 65 is: Quote: | $objCache->save($content, $fileid); |
Any suggestions for change or is this block impossible to cache? |
|
|
|
 |
Raven

|
Posted:
Fri Jul 22, 2005 7:20 pm |
|
Are you using my admin module? What are a couple of the lines right above that line? |
|
|
|
 |
dean

|
Posted:
Fri Jul 22, 2005 7:28 pm |
|
I'm not using the admin module yet. I will install that once I get this block thingy working. It's a block that sees alot of views with perhaps 2 or three new additions a week.
Heres the last 10 lines of the block without the cache line inserted:
Code:$ZCcontent = "<table border=\"0\" width=\"100%\">";
$time = time();
$query = "SELECT ad_id, cat_id, subject, views FROM ".$user_prefix."_zclassifieds_ads WHERE exp_date > $time ORDER BY add_date DESC LIMIT 10";
$result = sql_query($query, $dbi);
$totalAds = sql_num_rows( sql_query( "SELECT cat_id FROM ".$user_prefix."_zclassifieds_ads WHERE exp_date > $time" , $dbi) , $dbi);
if( sql_num_rows( $result, $dbi ) != 0 ){
$ZCcontent .= "<tr><td colspan=\"2\"><b>"._ZCLASSIFIEDTOTALADS."$totalAds</b></td></tr>";
$ZCcontent .= "<tr><td colspan=\"2\"><b>"._ZCLASSIFIEDHOT."</b></td></tr>";
while( $row = sql_fetch_array( $result, $dbi ) ){
$ZCcontent .= "<tr><td valign=\"top\"><strong><big>·</big></strong></td><td width=\"100%\"><a href=\"modules.php?name=ZClassifieds&file=detail&cat={$row['cat_id']}&de={$row['ad_id']}\">{$row['subject']}</a> ({$row['views']})";
$ZCcontent .= "</td></tr>";
}
}
else
{
$ZCcontent .= "<tr><td width=\"100%\">"._ZCLASSIFIEDNOADDS."";
$ZCcontent .= "</a></td></tr>";
}
$ZCcontent .= "</table>";
$content .= $ZCcontent
?>
|
When I insert the line, I do like this:
Code: }
else
{
$ZCcontent .= "<tr><td width=\"100%\">"._ZCLASSIFIEDNOADDS."";
$ZCcontent .= "</a></td></tr>";
}
$ZCcontent .= "</table>";
$content .= $ZCcontent
// ...and save it in the cache for future use
$objCache->save($content, $fileid);
}
?>
|
|
|
|
|
 |
Raven

|
Posted:
Fri Jul 22, 2005 7:40 pm |
|
You have added a closing brace. Do you have an opening brace?Code:// ...and save it in the cache for future use
$objCache->save($content, $fileid);
}
|
|
|
|
|
 |
dean

|
Posted:
Fri Jul 22, 2005 8:25 pm |
|
Yes at top of block below:
Code:if (eregi("block-ZClassified.php", $PHP_SELF)) {
Header("Location: index.php");
die();
}
// include the Cache-Lite package
require_once("includes/Cache/Lite.php");
// set some variables
$options = array(
"cacheDir" => "tmp/Cache_Lite/",
"lifeTime" => 900
);
// create a Cache_Lite object
$objCache = new Cache_Lite($options);
// test if there exists a valid cache,
// the ID will be the basename of the block
$fileid = basename($blockfile,".php");
if ($content = $objCache->get($fileid)) {
// add a message indicating this is cached output
// $content .= "\n[cached with ID=$fileid]";
}
else
{
// do the block's work here...
|
|
|
|
|
 |
Raven

|
Posted:
Fri Jul 22, 2005 9:08 pm |
|
I just noticedCode:$objCache->save($content, $fileid);
| should beCode:$objCache->save($content);
|
|
|
|
|
 |
dean

|
Posted:
Fri Jul 22, 2005 10:15 pm |
|
Sorry to say, same error produced with that edit........... |
|
|
|
 |
Raven

|
Posted:
Fri Jul 22, 2005 11:07 pm |
|
That error usually means that there's a missing or mismatched () or {}. Check your code real close to be sure that you have your () and {} matched properly. |
|
|
|
 |
|