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  
Style-Sheets  
Web Services  
XML  
Zend  
Zope  
Forums Sitemap 
IBM® developerWorks 
Sun Developer Network 
E-Commerce Hosting 
Linux Web Hosting 
Managed Hosting 
Small Business Hosting 
Mobile Linux 
App Generation ROI 
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? 
PHP

Caching With PHP Cache_Lite
By: icarus, (c) Melonfire
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 4 stars4 stars4 stars4 stars4 stars / 19
    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:
      Del.ici.ous Digg
      Blink Simpy
      Google Spurl
      Y! MyWeb 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

    - Authentication Scripts for a User Management...
    - Utilizing the Use Keyword for Namespaces in ...
    - Building a User Management Application
    - Working With Different Namespaces in PHP 5
    - User Management Explained: Overview
    - Using Namespaces in PHP 5
    - Database Security: Guarding Against SQL Inje...
    - Building a Modular Exception Class in PHP 5
    - Database and Password Security for Web Appli...
    - Handling MySQL Data Set Failures in PHP 5
    - Building Site Registration for Web Applicati...
    - Intercepting Customized Exceptions in PHP 5
    - Securing Your Web Application Against Attacks
    - Sub Classing Exceptions in PHP 5
    - Authentication for Web Application Security





    © 2003-2008 by Developer Shed. All rights reserved. DS Cluster 1 hosted by Hostway
    Stay green...Green IT