zf Framework zend_cache Cache Usage Method of zend Framework

  • 2021-01-25 07:22:09
  • OfStack

Zend_Cache file cache of the basic operation, the code has written comments, we learn 1 together


<?php
require_once("Zend/Loader.php");
// load Zend The cache class (Zend_Cache)
Zend_Loader::loadClass("Zend_Cache");
// Front-end cache Settings ( Lifecycle, serialization or not )
$Foptions = array('lifetime' => 60 , 'automtic_Serialization' => true);
// Backend cache Settings ( Cache store path )
$Boptions = array('cacheDir' => 'cache');
// Enable cache mode ,(Core[ The core ],File[ file ], Front-end cache configuration information, back-end cache configuration information )
$Cache = Zend_Cache::factory('Core','File',$Foptions,$Boptions);
// Determine if the cache exists and, if so, load the cache load('String'[ Name of the cache ])
if ($Result = $Cache -> load('cache_two')) 
{
 echo " The cache already exists! <br>";
 print_r($Result);
}
else
{
 // If the cache does not exist, the file is read and the contents of the file are written to the lake cache 
 echo " Cache doesn't exist! <br>";
 $Filename = 'temp.txt';
 $Fopen    = fopen($Filename,'r');
 $Result   = fread($Fopen, filesize($Filename));
 fclose($Fopen);
 // Save cache mode load($Result[ Read the resource ],' Name of the cache ')
 $Cache -> save($Result,'cache_two');
 print_r($Result);
}
?>


Related articles: