PDA

View Full Version : Delay loading home page of site after cache fix


Raid
11-01-09, 17:02
Hi All

After implementing the cache fix (see below) my site now has a few seconds delay when loading the home page :( . However, pages such as productlist.php experience no delay if I have created a link direct to that.

Any ideas? The cache fix I implemented was:

If you place the following into your index.php file:

Code:

// Clear the smarty cache for docs older than 60mins
$oSmarty->clear_all_cache(3600);

Right below where you initialize your smarty object.

Thanks all

Raid :cool:

amcho
12-01-09, 15:43
I guess that each time the script with the
$oSmarty->clear_all_cache(3600);
code is loaded you are reading the smarty cache directory,
checking how old each file is
and deleting any that are over 3600 years old.

Solutions:
create a copy of your home page and run that manually, say once a day,
or create a cron job that clears out the smarty cache directory,

Raid
12-01-09, 17:05
OK, thanks, I will look into implementing those suggestions. :)

Out of interest, has anyone else experienced this problem and how did you choose to solve it?

Thanks

Raid

Raid
12-01-09, 22:38
If I extract some of the code related to the Smarty object and cache clearance, and put it into a separate .php script as per the below, is that going to get the cache clearance done? I've tried this and when I run the script it doesn't have any delay until "Cache Cleared" gets echoed, unlike the delay experienced when the code is in index.php, and that's making me wonder whether it's working. :confused:

Thanks :cool:

<?php
require_once('constants.inc.php');

include_once('status.php'); // detect any basic setup errors

require_once('classes'.DIRECTORY_SEPARATOR.'class. smarty_sw.php');

// init Smarty
$oSmarty = new smarty_sw();

// fix for cache clearance
// Clear the smarty cache for docs older than 60mins
$oSmarty->clear_all_cache(3600);

echo "Cache cleared";
?>