id = $id; $this->ttl = $ttl; $this->cacheCWD = getcwd(); $cachemethod = "cache$method"; $this->cache = new $cachemethod (); $res = $this->cache->read ($id); // If there is a cache : display it if ($res !== false) { foreach ($res["headers"] as $header) @header ($header); echo $res["content"]; exit; } ob_start (); $this->saving = true; // The datas are sent automatically } /** End of saving the datas in cache */ public function __destruct () { // Force the path because it return to / in the destructor chdir ($this->cacheCWD); if ($this->saving === true) { // Do the saving of the datas $datas = array ("content"=>ob_get_contents (), "headers"=>headers_list ()); $this->cache->write ($this->id, $datas, $this->ttl); } } }