ของมูลที่จะเอาไปใช้ จะอยู่ใน $data
โค้ด: เลือกทั้งหมด
<?php
include 'library/Zend/Cache.php';
$frontendOptions = array(
'lifetime' => 10,
'automatic_serialization' => true
);
$backendOptions = array(
'cache_dir' => 'tmp/'
);
$cache = Zend_Cache::factory('Core', 'File', $frontendOptions, $backendOptions);
$id = 'myBigLoop';
$start_time = microtime(true);
if(!($data = $cache->load($id)))
{
echo "Not found in Cache<br />";
$data = ”;
for ($i = 0; $i < 1000000; $i++)
{
$data = $data . $i;
}
$cache->save($data);
}
else
{
echo "Running from Cache<br />";
}
echo sprintf('%01.4f', microtime(true) – $start_time);