All pastes #753245 Raw Edit

Untitled

public text v1 · immutable
#753245 ·published 2007-10-29 01:50 UTC
rendered paste body
<?php

class cache {

function __construct(){
  if(!file_exists('cache.txt')){
    touch('cache.txt');
  }
}

public function cache($param){
  $param = serialize($param);
  file_put_contents('cache.txt', $param);
  return true;
}

public function staff_cache(){
  $param = unserialize(file_get_contents('cache.txt'));
  return $param;
}

}

// generate array
$i = 0; while($i < 100){
  $array[$i] = $i;
  $i++;
}

// create new instance
$instance = new cache();

// cache $array
$instance->cache($array);

// collect cached $array
$getCache = $instance->staff_cache();
print_r($getCache);

?>