PHP Classes

File: example.php

Recommend this page to a friend!
  Classes of Stanislav Chervenkov   File Cache   example.php   Download  
File: example.php
Role: Example script
Content type: text/plain
Description: An example using the class
Class: File Cache
Store and retrieve generic data in cache files
Author: By
Last change:
Date: 15 years ago
Size: 693 bytes
 

Contents

Class file image Download
<?php
require_once ('cache.class.php');
$cache = new cache();
/**
* E X A M P L E
* Caching search details from any database
*/
$search_string = urldecode($_GET['s']);

// check if there is a cache for this search string
if (!$cache->read($result, "SEARCH_RESULTS_".$search_string)) {

   
// if there is no cache, make a query and get the result
   
$sql = "SELECT * FROM `results` WHERE `searched_str` LIKE '".addslashes($search_string)."'";
   
$query = mysql_query($sql);
   
$result = mysql_fetch_assoc($query);

   
// cache the result for 1 hour (3600 sec)
   
$cache->set($result, "SEARCH_RESULTS_".$search_string, 3600);
}

print
"<pre>";
print_r ($result);
print
"</pre>";
?>