Home >Backend Development >PHP Tutorial >Zend Framework cache Cache usage simple example, zendframework_PHP tutorial

Zend Framework cache Cache usage simple example, zendframework_PHP tutorial

WBOY
WBOYOriginal
2016-07-12 08:56:34917browse

A simple example of Zend Framework Cache usage, zendframework

The example in this article describes the usage of Zend Framework Cache. Share it with everyone for your reference, the details are as follows:

<&#63;php
require 'Zend/Loader.php';
Zend_Loader::loadClass('Zend_Cache');
Zend_Loader::loadClass('Zend_Config');
Zend_Loader::loadClass('Zend_Registry');
$config = new Zend_Config_Ini('configsecr/config.ini');
define('CACHE_DIR',FDROOT.'/'.'tmp/');
/*
配置文件config.ini:
[cache]
cache.needcache=1
cache.frontend.name=Core
cache.frontend.lifetime=7200
cache.frontend.automatic_serialization=1
cache.backend.name=File
*/
/*选项参考手册*/
/*建立cache对象*/
$frontendOptions = $config->cache->cache->frontend->toArray();
$backendOptions = $config->cache->cache->backend->toArray();
$frontendName = $frontendOptions['name'];
unset($frontendOptions['name']);
$backendName = $backendOptions['name'];
unset($backendOptions['name']);
if (empty($backendOptions['cache_dir']))
{
 $backendOptions['cache_dir'] = CACHE_DIR;
}
$_cache = Zend_Cache::factory($frontendName, $backendName, $frontendOptions, $backendOptions);
Zend_Registry::set('cache', $_cache);
/*使用cache*/
$viewRenderer = $_cache->load('viewRenderer'); //试图从缓存加载变量
if (!$viewRenderer instanceof Something)//加载不成功
{
 $viewRenderer = new Something();
 /*some other work*/
 $_cache->save($viewRenderer, 'viewRenderer');//保存变量到换存
}
/*这只是一种应用,还可以轻松缓存整页;也可将缓存存到数据库或者内存。*/
&#63;>

Readers who are interested in more zend-related content can check out the special topics of this site: "Zend FrameWork Framework Introductory Tutorial", "php Excellent Development Framework Summary", "Yii Framework Introduction and Summary of Common Techniques", "ThinkPHP Introductory Tutorial" , "php object-oriented programming introductory tutorial", "php mysql database operation introductory tutorial" and "php common database operation skills summary"

I hope this article will be helpful to everyone’s PHP programming based on the Zend Framework framework.

Articles you may be interested in:

  • Zend Framework's Zend_Mail implements the verification function of sending email and solves the problem of garbled headers
  • Zend Framework tutorial's Zend_Form component implementation form Methods to submit and display error prompts
  • Zend Framework implementation of multi-file upload function example
  • Environment configuration for getting started with Zend Framework and the first Hello World example (with demo source code download)
  • Zend Framework Tutorial: How to connect to the database and perform add/delete queries (with demo source code download)
  • Zend Framework Tutorial: Zend_Db_Table_Rowset Usage Example Analysis
  • Zend Framework Tutorial: Zend_Db_Table_Row Usage Example
  • Detailed explanation of Zend_Db_Table usage in Zend Framework tutorial
  • Summary of Zend Framework entry knowledge points
  • Zend Framework basic page layout analysis
  • Zend Framework generates verification codes and implements verification Code verification function (with demo source code download)

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/1111887.htmlTechArticleA simple example of Zend Framework Cache usage, zendframework This example describes the usage of Zend Framework Cache. Share it with everyone for your reference, the details are as follows: phprequire 'Zend...
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn