Ravens PHP Scripts: Forums
 

 

View next topic
View previous topic
Post new topic   Reply to topic    Ravens PHP Scripts And Web Hosting Forum Index -> Cache Lite Admin Module
Author Message
dean
Worker
Worker


Joined: Apr 14, 2004
Posts: 193

PostPosted: Fri Jul 22, 2005 1:23 pm Reply with quote

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).
 
View user's profile Send private message
Raven
Site Admin/Owner


Joined: Aug 27, 2002
Posts: 17077

PostPosted: Fri Jul 22, 2005 3:42 pm Reply with quote

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
 
View user's profile Send private message
dean
PostPosted: Fri Jul 22, 2005 7:13 pm Reply with quote

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
PostPosted: Fri Jul 22, 2005 7:20 pm Reply with quote

Are you using my admin module? What are a couple of the lines right above that line?
 
dean
PostPosted: Fri Jul 22, 2005 7:28 pm Reply with quote

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>&middot;</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
PostPosted: Fri Jul 22, 2005 7:40 pm Reply with quote

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
PostPosted: Fri Jul 22, 2005 8:25 pm Reply with quote

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
PostPosted: Fri Jul 22, 2005 9:08 pm Reply with quote

I just noticed
Code:
$objCache->save($content, $fileid);
should be
Code:
$objCache->save($content);
 
dean
PostPosted: Fri Jul 22, 2005 10:15 pm Reply with quote

Sorry to say, same error produced with that edit...........
 
Raven
PostPosted: Fri Jul 22, 2005 11:07 pm Reply with quote

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.
 
Display posts from previous:       
Post new topic   Reply to topic    Ravens PHP Scripts And Web Hosting Forum Index -> Cache Lite Admin Module

View next topic
View previous topic
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You can attach files in this forum
You can download files in this forum


Powered by phpBB © 2001-2007 phpBB Group
All times are GMT - 6 Hours
 
Forums ©