public function cache($path, $lifetime = 3600, $compress = true, $chmod = 0755) {

        // if caching is not explicitly disabled
        if ($path !== false) {

            // if path doesn't exist, attempt to create it
            if (!is_dir($path)) @mkdir($path, $chmod, true);

            // save cache-related properties
            $this->cache = array(
                'path'      =>  $path,
                'lifetime'  =>  $lifetime,
                'chmod'     =>  $chmod,
                'compress'  =>  $compress,
            );

        // if caching is explicitly disabled, set this property to FALSE
        } else $this->cache = false;

    }
public function cache($path, $lifetime = 3600, $compress = true, $chmod = 0755) {

        // if caching is not explicitly disabled
        if ($path !== false) {

            // if path doesn't exist, attempt to create it
            if (!is_dir($path)) @mkdir($path, $chmod, true);

            // save cache-related properties
            $this->cache = array(
                'path'      =>  $path,
                'lifetime'  =>  $lifetime,
                'chmod'     =>  $chmod,
                'compress'  =>  $compress,
            );

        // if caching is explicitly disabled, set this property to FALSE
        } else $this->cache = false;

    }
public function cache ( $ path , $ lifetime = 3600 , $ compress = true , $ chmod = 0755 ) { // if caching is not explicitly disabled if ( $ path !== false ) { // if path doesn't exist, attempt to create it if ( ! is_dir ( $ path ) ) @ mkdir ( $ path , $ chmod , true ) ; // save cache-related properties $ this -> cache = array ( 'path' => $ path , 'lifetime' => $ lifetime , 'chmod' => $ chmod , 'compress' => $ compress , ) ; // if caching is explicitly disabled, set this property to FALSE } else $ this -> cache = false ; }
Use this method to enable caching of requests.

<i>Note that only the actual request is cached and not associated downloads, if any!</i>

<i>Caching is disabled by default!</i>

<code>
// the callback function to be executed for each and every
// request, as soon as a request finishes
// the callback function receives as argument an object with 4 properties
// (info, header, body and response)
function mycallback($result) {

// everything went well at cURL level
if ($result->response[1] == CURLE_OK) {

// if server responded with code 200 (meaning that everything went well)
// see http://httpstatus.es/ for a list of possible response codes
if ($result->info['http_code'] == 200) {

// see all the returned data
print_r('<pre>');
print_r($result);

// show the server's response code
} else die('Server responded with code ' . $result->info['http_code']);

// something went wrong
// ($result still contains all data that could be gathered)
} else die('cURL responded with: ' . $result->response[0]);

}

// include the Zebra_cURL library
require 'path/to/Zebra_cURL';

// instantiate the Zebra_cURL object
$curl = new Zebra_cURL();

// cache results in the "cache" folder and for 86400 seconds (24 hours)
$curl->cache('cache', 86400);

// let's fetch the RSS feeds of some popular tech-related websites
// execute the "mycallback" function for each request, as soon as it finishes
$curl->get(array(
'http://feeds.feedburner.com/alistapart/main',
'http://feeds.feedburner.com/TechCrunch',
'http://feeds.mashable.com/mashable',
), 'mycallback')
</code>

@param  string      $path       Path where cache files to be stored.

Setting this to FALSE will disable caching.

<i>If set to a non-existing path, the library will try to create the folder
and will trigger an error if, for whatever reasons, it is unable to do so. If the
folder can be created, its permissions will be set to the value of $chmod</i>

@param  integer     $lifetime   (Optional) The number of seconds after which cache will be considered expired.

Default is 3600 (one hour).

@param  boolean     $compress   (Optional) If set to TRUE, cache files will be
{@link http://php.net/manual/en/function.gzcompress.php gzcompress}-ed  so that
they occupy less disk space.

Default is TRUE.

@param  octal       $chmod      (Optional) The file system permissions to be set for newly created cache files.

I suggest using the value "0755" (without the quotes) but, if you know what you
are doing, here is how you can calculate the permission levels:

- 400 Owner Read
- 200 Owner Write
- 100 Owner Execute
- 40 Group Read
- 20 Group Write
- 10 Group Execute
- 4 Global Read
- 2 Global Write
- 1 Global Execute

Default is "0755" (without the quotes).

@return void
Use this method to enable caching of requests .