PHP Classes
elePHPant
Icontem

File: example.php

Recommend this page to a friend!
Stumble It! Stumble It! Bookmark in del.icio.us Bookmark in del.icio.us
  Classes of Md. Rayhan Chowdhury  >  Ray Cache  >  example.php  >  Download  
File: example.php
Role: Example script
Content type: text/plain
Description: Example File
Class: Ray Cache
Store and retrieve cache data in files
Author: By
Last change:
Date: 4 years ago
Size: 2,179 bytes
 

Contents

Class file image Download
<?php
   
/**
     * Load the cache library
     *
     */
   
include_once('raycache.php');

   
/**
     * Class Example
     *
     * Once loaded you can use this class in two ways:
     * - Using Static Methods (My Favorite)
     * - Using Class Instance
     *
     * or, even you can mix them both
     * In both ways it support multiple configuration and uses
     */

    /**
     * Static Method
     */

    //Get default CacheInstance with one of the following methods
   
RayCache::getInstance();

   
// OR
   
RayCache::getInstance(null, null, array('path' => 'my_cache_path/', 'prefix' => 'my_cache_', 'expire' => '+10 seconds'));

   
// You can configure or reconfigure your instance anytime you like.
   
RayCache::getInstance()->config(array('path' => 'my_cache_path/', 'prefix' => 'my_cache_', 'expire' => '+10 seconds'));

   
// store data
   
RayCache::write('test_key', 'This data will expire in 10 seconds<br />');
   
RayCache::write('test_key2', 'This data will expire in 10 seconds<br />', array('expire' => '+10 seconds')); // expre value can be integer in seconds or time string supported by php strtotime method
   
RayCache::write('test_key3', 'This data will expire in 20 seconds<br />', array('expire' => '+20 seconds'));

   
// read data
   
echo RayCache::read('test_key');
    echo
RayCache::read('test_key2');
    echo
RayCache::read('test_key3');



   
   
/**
     * Class Instance Method
     */

    // get calss class instance
   
$cache = RayCache::getInstance(); // default configure
   
$cache2 = RayCache::getInstance('short', null, array('prefix' => 'short_', 'path' => 'my_cache_path/', 'expire' => '+20 seconds'));
   
$cache3 = RayCache::getInstance('long', null, array('prefix' => 'long_', 'path' => 'my_cache_path/', 'expire' => '+1 hour'));

   
// store data
   
$cache->write('test_key', 'This data will expire in 10 seconds<br />');
   
$cache2->write('test_key2', 'This data will expire in 20 seconds<br />');
   
$cache3->write('test_key3', 'This data will expire in 1 hour<br />');

   
// read data
   
echo $cache->read('test_key');
    echo
$cache2->read('test_key2');
    echo
$cache3->read('test_key3');
?>