A small example of ZendCache usage in 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
*/
/* Option Reference Manual */
/* Create a cache object */
$ FrontendOptions = $ config-> cache-> frontend-> toArray ();
$ BackendOptions = $ config-> 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 );
/* Use cache */
$ ViewRenderer = $ _ cache-> load ('viewrenderer '); // try to load variables from the cache
If (! $ ViewRenderer instanceof Something) // loading failed
{
$ ViewRenderer = new Something ();
/* Some other work */
$ _ Cache-> save ($ viewRenderer, 'viewrenderer'); // save the variable to the swap
}
/* This is just an application. It can also easily cache the entire page, or save the cache to the database or memory. */
?>