Home > php教程 > php手册 > body text

Zend Framework缓存Cache用法简单实例,zendframework

WBOY
Release: 2016-06-13 08:44:02
Original
951 people have browsed it

Zend Framework缓存Cache用法简单实例,zendframework

本文实例讲述了Zend Framework缓存Cache用法。分享给大家供大家参考,具体如下:

<&#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;>

Copy after login

更多关于zend相关内容感兴趣的读者可查看本站专题:《Zend FrameWork框架入门教程》、《php优秀开发框架总结》、《Yii框架入门及常用技巧总结》、《ThinkPHP入门教程》、《php面向对象程序设计入门教程》、《php+mysql数据库操作入门教程》及《php常见数据库操作技巧汇总》

希望本文所述对大家基于Zend Framework框架的PHP程序设计有所帮助。

您可能感兴趣的文章:

  • Zend Framework框架之Zend_Mail实现发送Email邮件验证功能及解决标题乱码的方法
  • Zend Framework教程之Zend_Form组件实现表单提交并显示错误提示的方法
  • Zend Framework实现多文件上传功能实例
  • Zend Framework入门之环境配置及第一个Hello World示例(附demo源码下载)
  • Zend Framework教程之连接数据库并执行增删查的方法(附demo源码下载)
  • Zend Framework框架教程之Zend_Db_Table_Rowset用法实例分析
  • Zend Framework教程之Zend_Db_Table_Row用法实例分析
  • Zend Framework教程之Zend_Db_Table用法详解
  • Zend Framework入门知识点小结
  • Zend Framework基本页面布局分析
  • Zend Framework生成验证码并实现验证码验证功能(附demo源码下载)
Related labels:
source:php.cn
Statement of this Website
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
Popular Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template