include class require_once cache php create object cache new Cache che

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
<?
// include class
require_once('cache.php');
// create object
$cache = new Cache();
// checking the existence of the cache
$data = $cache->read('test_17.tmp'); //17 this example id of article
// if cache doesn't exist get article from database
if (empty($data)) {
$sql = "SELECT image, user_id, content FROM table WHERE id = 17";
$data = $db->select_list($sql); // just for example
$cache->write('test_17.tmp', $data);
}
// next use data what always
foreach($data as $row) {
........
}