Simple ZendFramework Cache Usage example

Source: Internet
Author: User
This example describes the ZendFramework Cache usage. For your reference, see phprequireZendLoader. php; Zend_Loader: loadClass (Zend_Cache); Zend_Loader: loadClass (Zend_Config); Zend_Loader: loadClass (Zend_Registry); $ confignewZend _

This example describes the Zend Framework Cache usage. For your reference, see phprequire 'zend/Loader. php '; Zend_Loader: loadClass ('zend _ cache'); Zend_Loader: loadClass ('zend _ config'); Zend_Loader: loadClass ('zend _ Registry '); $ config = new Zend _

This example describes the Zend Framework Cache usage. We will share this with you for your reference. The details are as follows:

<? Phprequire '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 = 1cache. frontend. name = Corecache. frontend. lifetime = 7200cache. frontend. automatic_serialization = 1cache. 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 ($ fro NtendName, $ backendName, $ frontendOptions, $ backendOptions); Zend_Registry: set ('cache', $ _ cache ); /* use cache */$ viewRenderer =$ _ cache-> load ('viewrenderer'); // try to load the variable if (! $ ViewRenderer instanceof Something) // loading failed {$ viewRenderer = new Something ();/* some other work */$ _ cache-> save ($ viewRenderer, 'viewrenerer'); // Save the variable to the memory change}/* this is only an application that can easily cache the entire page or store the cache in the database or memory. */?>

Related Article

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.