Login   Register  
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 wanglei  >  secache  >  example.php  >  Download  
File: example.php
Role: Example script
Content type: text/plain
Description: write and read
Class: secache
Store and retrieve cached values from single file
Author: By
Last change:
Date: 2010-03-11 20:59
Size: 836 bytes
 

Contents

Class file image Download
<?php
require('secache.php');
$cache = new secache;
$cache->workat('cachedata');

function 
microtime_float(){
    list(
$usec$sec) = explode(" "microtime());
    return ((float)
$usec + (float)$sec);
}

$begin_time microtime_float();

for(
$i=0;$i<1000;$i++){

    
$key md5($i); //You must *HASH* it by your self
    
$value str_repeat('No. <strong>'.$i.'</strong> is <em style="color:red">great</em>! ',rand(1,10)); // must be a *STRING*

    
$cache->store($key,$value);
}

echo 
'<h2>Insert x 1000 = ' .( microtime_float() - $begin_time) .' ms</h2>';
echo 
'<hr /><h2>test read</h2>';

for(
$i=0;$i<1000;$i+=200){

    
$key md5($i); //You must *HASH* it by your self
    
if($cache->fetch($key,$value)){
        echo 
'<li>'.$key.'=>'.$value.'</li>';
    }else{
        echo 
'<li>Data get failed! <b>'.$key.'</b></li>';
    }
}
?>