PHP
  Home arrow PHP arrow Page 3 - Caching With PHP Cache_Lite
Dev Shed Forums  
Administration  
AJAX  
Apache  
BrainDump  
DHTML  
Flash  
Java  
JavaScript  
Multimedia  
MySQL  
Oracle  
Perl  
PHP  
Practices  
Python  
Reviews  
Security  
Smartphone Development  
Style-Sheets  
Web Services  
XML  
Zend  
Zope  
Mobile Linux  
App Generation ROI  
IBM® developerWorks  
Forums Sitemap  
E-Commerce Hosting  
Linux Web Hosting  
Managed Hosting  
Small Business Hosting  
VPS Hosting  
Weekly Newsletter

 
Developer Updates  
Free Website Content 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us Get Paid  
Request Media Kit
Contact Us  
Site Map  
Privacy Policy  
Support  
 USERNAME
 
 PASSWORD
 
 
  >>> SIGN UP!  
  Lost Password? 
Google.com  
PHP

Caching With PHP Cache_Lite
By: icarus, (c) Melonfire
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: starstarstarstarstar / 20
    2003-06-06


    Table of Contents:
  • Caching With PHP Cache_Lite
  • The Food Chain
  • Return Of The Jedi
  • Digging Deeper
  • In And Out
  • Bits And Bytes
  • No News Is Good News
  • Cache Cow
  • Endgame

  • Rate this Article: Poor Best 
      ADD THIS ARTICLE TO:
      error-file:tidyout.log Del.ici.ous error-file:tidyout.log Digg
      error-file:tidyout.log Blink error-file:tidyout.log Simpy
      error-file:tidyout.log Google error-file:tidyout.log Spurl
      error-file:tidyout.log Y! MyWeb error-file:tidyout.log Furl
    Email Me Similar Content When Posted
    Add Developer Shed Article Feed To Your Site
    Email Article To Friend
    Print Version Of Article
    PDF Version Of Article

     
     
    ADVERTISEMENT


    Caching With PHP Cache_Lite - Return Of The Jedi
    ( Page 3 of 9 )

    The Cache_Lite class comes courtesy of PEAR, the PHP Extension and Application Repository (http://pear.php.net). In case you didn't know, PEAR is an online repository of free PHP software, including classes and modules for everything from data archiving to XML parsing. When you install PHP, a whole bunch of PEAR modules get installed as well; the Cache_Lite class is one of them.

    In case your PHP distribution didn't include Cache_Lite, you can get yourself a copy from the official PEAR Web site, at http://pear.php.net - simply unzip the distribution archive into your PEAR directory and you're ready to roll!

    Let's begin with something simple - building a primitive cache using Cache_Lite object methods. Here's the code:

    
    

    <?php


    // include the package

    require_once("Lite.php");


    // set an ID for this cache

    $id = "starwars";


    // set some variables

    $options = array(

    "cacheDir" => "cache/",

    "lifeTime" => 50

    );


    // create a Cache_Lite object

    $objCache = new Cache_Lite($options);


    // test if there exists a valid cache

    if ($quote = $objCache->get($id))

    {

    // if so, display it

    echo $quote;



    // add a message indicating this is cached output

    echo " [cached]";

    }

    else

    {

    // no cached data

    // implies this data has not been requested in last cache lifetime

    // so obtain it and display it

    $quote = "Do, or do not. There is no try. -- Yoda, Star Wars";

    echo $quote;



    // also save it in the cache for future use

    $objCache->save($quote, $id);

    }


    ?>

    Don't worry if it didn't make too much sense - all will be explained shortly. For the moment, just feast your eyes on the output:


    Do, or do not. There is no try. -- Yoda, Star Wars

    Now refresh the page - you should see something like this, indicating that the second occurrence of the page has been retrieved from the cache.


    Do, or do not. There is no try. -- Yoda, Star Wars [cached]

    Let's take a closer look at how this was accomplished, on the next page.



     
     
    >>> More PHP Articles          >>> More By icarus, (c) Melonfire
     

       

    PHP ARTICLES

    - Merging a File Split for FTP Upload using PHP
    - Getting Data from Yahoo Site Explorer Inboun...
    - Method Chaining: Adding More Selecting Metho...
    - How to Split a File During an FTP Upload Usi...
    - Expanding a Custom CodeIgniter Library with ...
    - Using the Yahoo Site Explorer Inbound Links ...
    - Building a CodeIgniter Custom Library with M...
    - Building an E-mini Trading System Using PHP ...
    - Completing the MySQL Class with Method Chain...
    - Building Dynamic Queries with Chainable Meth...
    - PHP Encryption and Decryption Methods
    - Building a MySQL Abstraction Class with Meth...
    - Completing a Sample String Processor with Me...
    - Mastering WHILE Loops for PHP and MySQL
    - Method Chaining: Adding More Methods to the ...





    © 2003-2009 by Developer Shed. All rights reserved. DS Cluster 2 Hosted by Hostway
    For more Enterprise Application Development news, visit eWeek