#native_company# #native_desc#
#native_cta#

Creating a Printer Version Grab Method Page 6

By Jim Fletcher
on April 1, 2004

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.
Step 0: Define the function

<?php 

function cachesearch($url,$daystocache)

{
?>



Step 1: Calculate the maximum timestamp available

<?php 

$expiredate 
strtotime (&quot;-$daystocache days&quot;);

?>



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] .

1
|
2
|
3
|
4
|
5
|
6
|
7
|
8
|
9
|