Zend Framework Caching cache usage Simple instance _php instance

Source: Internet
Author: User
The examples in this article describe the cache usage of Zend Framework caches. Share to everyone for your reference, 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 ');d efine (' CACHE_DIR ') , Fdroot. ' /'.' tmp/');/* configuration file Config.ini:[cache]cache.needcache=1cache.frontend.name=corecache.frontend.lifetime= 7200cache.frontend.automatic_serialization=1cache.backend.name=file*//* option Reference manual *//* creating the 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 '); Attempting to load variable i from cacheF (! $viewRenderer instanceof Something)//load unsuccessful {$viewRenderer = new Something ();/*some other work*/$_cache->save ($vi Ewrenderer, ' viewrenderer ');//save variables to swap}/* This is an app, it's easy to cache entire pages, or you can store the cache in a database or memory. */?>

More interested in Zend related content readers can view the topic: "Zend framework of the introductory tutorial", "PHP Excellent Development Framework Summary", "Yii framework Introduction and common skills Summary", "thinkphp Introductory Tutorial", "PHP object-oriented Programming introduction tutorial "," Introduction to Php+mysql Database Operation "and" PHP common database Operation Skills Summary "

It is hoped that this article will help you to design PHP based on the Zend Framework 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.