Zend Framework缓存Cache用法简单实例
程序员文章站
2022-05-09 14:27:49
...
本文实例讲述了Zend Framework缓存Cache用法。分享给大家供大家参考,具体如下:
<?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');//保存变量到换存 } /*这只是一种应用,还可以轻松缓存整页;也可将缓存存到数据库或者内存。*/ ?>
希望本文所述对大家基于Zend Framework框架的PHP程序设计有所帮助。
更多Zend Framework缓存Cache用法简单实例相关文章请关注PHP中文网!
推荐阅读
-
Zend Framework框架教程之Zend_Db_Table_Rowset用法实例分析_php实例
-
YII Framework框架教程之缓存用法详解_php实例
-
Zend Framework分页类用法详解_php实例
-
Zend Framework教程之Application用法实例详解_php实例
-
Zend Framework教程之资源(Resources)用法实例详解,zendframework_PHP教程
-
Zend Framework教程之Loader以及PluginLoader用法详解_php实例
-
Zend Framework教程之分发器Zend_Controller_Dispatcher用法详解_php实例
-
Zend Framework教程之Autoloading用法详解_php实例
-
Zend Framework教程之前端控制器Zend_Controller_Front用法详解_php实例
-
Zend Framework教程之模型Model用法简单实例,zendframework_PHP教程