Search the cache for page content
Here we will build a function to see if this page is already in the MySQL
cache of page content. If it is in the cache, the function will only
return the data if it is not older than the number of days specified in the
options above.
cache of page content. If it is in the cache, the function will only
return the data if it is not older than the number of days specified in the
options above.
Step 0: Define the function
<?php
function cachesearch($url,$daystocache)
{?>
Step 1: Calculate the maximum timestamp available
<?php
$expiredate = strtotime ("-$daystocache days");
?>
Step 2: Query database for matching URL and timestamp below the maximum allowed
<?php
$sql = "SELECT * FROM cache WHERE url='$url' and date > '$expiredate'";
$result = mysql_query($sql);
$myrow = mysql_fetch_array($result);
?>
Step 3: If matching content is in the cache, return it
<?php
if (mysql_numrows($result)==1) {
$answer[0] = $myrow["title"];
$answer[1] = $myrow["body"];
return $answer;
}
?>
Step 4: If no match is found in the cache, return false
<?php
else {
return false;
}
?>
Step 5: End the function definition
<?php
} # end of cachesearch
?>
Step 6: Execute the function
<?php
$cacheurl = strtolower($url);
$resultb = cachesearch($cacheurl,$daystocache);
?>
Note: Any returned title will now be in variable $result[0]
and any returned body content will now be in variable $result[1] .
and any returned body content will now be in variable $result[1] .