Zend Framework Caching cache usage Simple instance _php instance

Source: Internet
Author: User
Tags zend zend framework

The example in this article describes the cache usage for Zend Framework caching. Share to everyone for your reference, specific as follows:

<?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/');
/* Configuration file Config.ini: [Cache] cache.needcache=1 Cache.frontend.name=core cache.frontend.lifetime=7200 Cache.frontend.automatic_serialization=1 cache.backend.name=file///////////////* Set Cache object/* $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); /* Use cache*/$viewRenderer = $_cache->loAD (' Viewrenderer ');
 An attempt was made to load a variable from the cache if (! $viewRenderer instanceof Something)//failed to load {$viewRenderer = new something (); /*some other work*/$_cache->save ($viewRenderer, ' viewrenderer ');/save variable to save}/* This is just an application, you can easily cache an entire page, or you can save the cache to a database or memory.

 * *?>

More interested in Zend related content readers can view the site topics: "The introduction of the Zend Framework frame", "PHP Excellent Development Framework Summary", "Yii framework Introduction and common skills Summary", "thinkphp Introductory Course", "PHP object-oriented Programming Program , "Php+mysql Database operation Introduction Tutorial" and "PHP common database Operation Skills Summary"

I hope this article will help you with the PHP program design based on the Zend Framework.

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.