From ac7b31b3a6ce014fdea3b8deea0956184fc0db91 Mon Sep 17 00:00:00 2001 From: Travis Tidwell Date: Fri, 16 Dec 2011 05:53:47 +0100 Subject: [PATCH] Adding a way to change the file cache directory. --- HTTP/FileCachedRequest.php | 14 +++++++++++++- HTTP/cache/README.md | 10 +++++++++- 2 files changed, 22 insertions(+), 2 deletions(-) diff --git a/HTTP/FileCachedRequest.php b/HTTP/FileCachedRequest.php index 4326f1f..91b4b3f 100644 --- a/HTTP/FileCachedRequest.php +++ b/HTTP/FileCachedRequest.php @@ -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); } diff --git a/HTTP/cache/README.md b/HTTP/cache/README.md index 2f7b6d4..0a90ff1 100644 --- a/HTTP/cache/README.md +++ b/HTTP/cache/README.md @@ -1 +1,9 @@ -This is where the FileCache is stored. \ No newline at end of file +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' +)); +