Simple caching in PHP5

I’ve just written a script that reads from a few webpages and I faced a problem of the servers sometime being slow and delaying my page display, so I decided to write a simple caching object:``` class cache {

function \_\_construct($path='.') {
    $this->path = $path;
}

function cache($name, $callback, $args) {
    if (file\_exists("$this->path/$name")) {
        $this->callbacks\[$name\] = array($callback, $args);
        return implode('', file("$this->path/$name"));
    } else {
        return $this->save($name, $callback, $args);
    }
}

function save($name, $callback, $args) {
    $text = call\_user\_func($callback, $args);
    $fh = fopen("$this->path/$name", 'w');
    fwrite($fh, $text);
    fclose($fh);
    return $text;
}

function \_\_desctruct() {
    if (is\_array($this->callbacks)) {
        foreach ($this->callbacks as $name => $callback) {
            list($callback, $args) = $callback;
            return $this->save($name, $callback, $args);
        }
    }
}

}

You call it using: $cache = new Cache(); $cache->cache(‘MyFunc.txt’, ‘MyFunc’, ‘an argument’);