ZF framework Zend_Cache basic usage

Source: Internet
Author: User
Learning to practice ZendFramework? Php * basic operations on Zend_Cache File Cache * require_once (ZendLoader. php); load Zend cache class (Zend_Cache) Zend_Loader: loadClass (Zend_Cache); front-end cache settings (lifecycle, serialization or not) $ Foptionsarray (lifetime60, automtic _

Learning to practice Zend Framework? Php/* basic operations on Zend_Cache File Cache */require_once ("Zend/Loader. php "); // load Zend cache class (Zend_Cache) Zend_Loader: loadClass (" Zend_Cache "); // front-end cache settings (lifecycle, serialization or not) $ Foptions = array ('lifetime' = 60, 'automtic _

Learning exercises
Zend Framework
 60, 'automtic _ serialization' => true); // backend cache settings (cache storage path) $ Boptions = array ('cachedir' => 'cache '); // enable the Cache mode. (Core [Core], File [File], frontend Cache configuration information, and backend Cache configuration information) $ Cache = Zend_Cache: factory ('core ', 'file', $ Foptions, $ Boptions); // determines whether the cache exists. If yes, load the cache ('string' [cache name]) if ($ Result = $ Cache-> load ('cache _ two') {echo "the cache already exists!
"; Print_r ($ Result);} else {// If the cache does not exist, read the file and write the file content into the lake cache echo" the cache does not exist!
"; $ Filename = 'temp.txt '; $ Fopen = fopen ($ Filename, 'R'); $ Result = fread ($ Fopen, filesize ($ Filename )); fclose ($ Fopen); // save Cache mode load ($ Result [read resource], 'cache name') $ Cache-> save ($ Result, 'cache _ two'); print_r ($ Result) ;}?>
 '2017. 0.0.1 ', 'username' => 'root', 'Password' => '000000', 'dbname' => 'test', 'filer' => "true "); $ Db = Zend_Db: factory ('pdo _ mysql', $ Config); $ Table = 'sanguo '; $ Select = $ Db-> select (); $ Select-> from ($ Table, '*'); $ Select-> Where ("s_sheng = 'hebei '"); $ Result = $ Db-> fetchAll ($ Select ); // ----------------- end ------------ // --- write the resources read from the database to the cache as Output --- // $ Foptions = array ('lifetime' => 3600, 'automtic _ S Erialization '=> true); $ Boptions = array ('cachedir' => 'cache'); $ cache = Zend_Cache: factory ('output', 'file ', $ Foptions, $ Boptions); if (! $ Cache-> start ('hebei10') {echo"
 
  
"; Foreach ($ Result as $ key => $ value) {echo"
  
    
"; Foreach ($ value as $ key2 => $ value2) {echo"
    ";} Echo"
   ";} Echo"
  
". $ Value2 ."
"; Echo" here is the cache time: ". date (" Y-m-d H: I: s ")."
"; $ Cache-> end ();} // ----- use the load () method to call and output the Cache ------ // echo" not cached here :". date ("Y-m-d H: I: s ")."
"; $ Result2 = $ Cache-> load ('hebei10'); echo $ Result2;?>
  3600 , 'automtic_Serialization' => true);$Boptions = array('cacheDir' => 'cache');$Cache = Zend_Cache::factory('Function','File',$Foptions,$Boptions);function GongBeiShu($num1,$num2){for ($i=$num1; $i <= $num2 ; $i++) { if ($i%3 == 0) {$Result[] = $i;}}return $Result;}$Cache -> call('GongBeiShu',array(1,50),array('temp_GongBeiShu'));$Date = $Cache ->call('GongBeiShu',array(1,50),array('temp_GongBeiShu'));print_r($Date);?>
 New test () you can call any permission method or 'cached _ entity '=> 'test'. Only static methods can be called */$ Foptions = array ('cached _ entity' => new test ()); // enable Cache (frontend, backend, and frontend configuration) $ Cache = Zend_Cache: factory ('class', 'file', $ Foptions); // The first call is written to the Cache, the second call will return; $ Cache-> sum (9); $ Cache-> cheng (9, 9); echo "sum () method returns the following result :". $ Cache-> sum (3, 3 )."
"; Echo" The result returned by the cheng () method is: ". $ Cache-> cheng )."
";?>
$ Cache = Zend_Cache: factory ('core', 'file', $ Foptions, $ Boptions ); if ($ Result = $ Cache-> load ('cache _ two') {echo "the cache already exists!
"; Print_r ($ Result); $ Cache-> clean ('all'); echo"
"; Echo" the cache has been cleared!
";}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.