<?php
include_once("CacheOS.Class.php");
// Example One (1)
// =================
$key = 'mydata'; // key to save cache with
//// get cached data from file cache
$data = CacheOS::get($key);
if($data === false) { // if data not found generate it
echo 'Not from cache.',"\n";
$data = 'This is processed data.';
CacheOS::save($key, $data); //// save data to file cache
} else {
echo 'From cache.',"\n";
}
echo $data,"\n"; // display the data
// Example Two (2)
// ==================
$key = 'mydata'; // key to save cache with
//// get cached data from file cache, also check if cached data is not older than 1 hour
$data = CacheOS::get($key, 3600);
if($data === false) { // if data not found generate it
echo 'Not from cache.',"\n";
$data = 'This is processed data and saved only for 1 hour.';
CacheOS::save($key, $data); //// save data to file cache
} else {
echo 'From cache.',"\n";
}
echo $data,"\n"; // display the data
// Example Three (3)
// ===================
$key = 'mydata'; // key to save cache with
$group = 'reports'; // group to save cache with in
//// get cached data from file cache within a group, put 0 for ttl if data should be cached infinite
$data = CacheOS::get($key, 0, $group);
if($data === false) { // if data not found generate it
echo 'Not from cache.',"\n";
$data = 'This is processed data saved within a group named as '.$group;
CacheOS::save($key, $data, $group); //// save data to file cache within a group
} else {
echo 'From cache.',"\n";
}
echo $data,"\n"; // display the data
// Cache clean examples
$key = 'mydata';
$group = 'reports';
if(CacheOS::deleteCache($key)) {
echo 'Cache Deleted.',"\n";
}
if(CacheOS::deleteCache($key, $group)) {
echo 'Cache Deleted within a group.',"\n";
}
//// this can be expensive as it parse all sub-directories & files within sub-directories
CacheOS::deleteGroupCache($group);
echo 'Cache Group deleted completly',"\n";
?>
|