Skip to content

Commit

Permalink
Adding a way to change the file cache directory.
Browse files Browse the repository at this point in the history
  • Loading branch information
travist committed Dec 16, 2011
1 parent 14714d9 commit ac7b31b
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 2 deletions.
14 changes: 13 additions & 1 deletion HTTP/FileCachedRequest.php
Expand Up @@ -11,12 +11,24 @@ class HTTP_FileCachedRequest extends HTTP_CachedRequest {
protected $cache_path = '';
protected $cache_exists = FALSE;

// The constructor.
function __construct($url = null, $method = self::METHOD_GET, array $config = array()) {

// Add the configuration for this class to the configuration.
$this->config = array_merge($this->config, array(
'cache_directory' => dirname(__FILE__) . '/cache'
));

// Call the parent constructor.
parent::__construct($url, $method, $config);
}

/**
* Sets the cache name.
*/
public function set_cache_name($cache_name) {
parent::set_cache_name($cache_name);
$this->cache_path = dirname(__FILE__) . '/cache/' . $cache_name;
$this->cache_path = $this->config['cache_directory'] . '/' . $cache_name;
$this->cache_exists = file_exists($this->cache_path);
}

Expand Down
10 changes: 9 additions & 1 deletion HTTP/cache/README.md
@@ -1 +1,9 @@
This is where the FileCache is stored.
This is where the FileCache is stored.

You can alter this at runtime by passing in the configuration of cache_directory
when declaring the request like so.

$request = new HTTP_FileCachedRequest('http://mysite.com/rest', 'GET', array(
'cache_directory' => '/tmp'
));

0 comments on commit ac7b31b

Please sign in to comment.