|
@@ -61,28 +61,22 @@ class Kohana_Cache_File extends Cache implements Cache_GarbageCollect {
|
|
|
protected $_cache_dir;
|
|
|
|
|
|
/**
|
|
|
- * Constructs the file cache driver. This method cannot be invoked externally. The file cache driver must
|
|
|
- * be instantiated using the `Cache::instance()` method.
|
|
|
+ * @var boolean does the cache directory is avaliable
|
|
|
+ */
|
|
|
+ protected $_inited = FALSE;
|
|
|
+
|
|
|
+ /**
|
|
|
+ * Creates the cache directory.
|
|
|
*
|
|
|
- * @param array $config config
|
|
|
* @throws Cache_Exception
|
|
|
*/
|
|
|
- protected function __construct(array $config)
|
|
|
+ protected function _init()
|
|
|
{
|
|
|
- // Setup parent
|
|
|
- parent::__construct($config);
|
|
|
-
|
|
|
try
|
|
|
{
|
|
|
$directory = Arr::get($this->_config, 'cache_dir', Kohana::$cache_dir);
|
|
|
$this->_cache_dir = new SplFileInfo($directory);
|
|
|
}
|
|
|
- // PHP < 5.3 exception handle
|
|
|
- catch (ErrorException $e)
|
|
|
- {
|
|
|
- $this->_cache_dir = $this->_make_directory($directory, 0777, TRUE);
|
|
|
- }
|
|
|
- // PHP >= 5.3 exception handle
|
|
|
catch (UnexpectedValueException $e)
|
|
|
{
|
|
|
$this->_cache_dir = $this->_make_directory($directory, 0777, TRUE);
|
|
@@ -105,6 +99,8 @@ class Kohana_Cache_File extends Cache implements Cache_GarbageCollect {
|
|
|
{
|
|
|
throw new Cache_Exception('Unable to write to the cache directory :resource', [':resource' => $this->_cache_dir->getRealPath()]);
|
|
|
}
|
|
|
+
|
|
|
+ $this->_inited = TRUE;
|
|
|
}
|
|
|
|
|
|
/**
|
|
@@ -123,6 +119,9 @@ class Kohana_Cache_File extends Cache implements Cache_GarbageCollect {
|
|
|
*/
|
|
|
public function get($id, $default = NULL)
|
|
|
{
|
|
|
+ // Make sure cache is inited
|
|
|
+ $this->_inited or $this->_init();
|
|
|
+
|
|
|
$filename = Cache_File::filename($this->_sanitize_id($id));
|
|
|
$directory = $this->_resolve_directory($filename);
|
|
|
|
|
@@ -197,6 +196,9 @@ class Kohana_Cache_File extends Cache implements Cache_GarbageCollect {
|
|
|
*/
|
|
|
public function set($id, $data, $lifetime = NULL)
|
|
|
{
|
|
|
+ // Make sure cache is inited
|
|
|
+ $this->_inited or $this->_init();
|
|
|
+
|
|
|
$filename = Cache_File::filename($this->_sanitize_id($id));
|
|
|
$directory = $this->_resolve_directory($filename);
|
|
|
|
|
@@ -251,6 +253,9 @@ class Kohana_Cache_File extends Cache implements Cache_GarbageCollect {
|
|
|
*/
|
|
|
public function delete($id)
|
|
|
{
|
|
|
+ // Make sure cache is inited
|
|
|
+ $this->_inited or $this->_init();
|
|
|
+
|
|
|
$filename = Cache_File::filename($this->_sanitize_id($id));
|
|
|
$directory = $this->_resolve_directory($filename);
|
|
|
|
|
@@ -271,6 +276,9 @@ class Kohana_Cache_File extends Cache implements Cache_GarbageCollect {
|
|
|
*/
|
|
|
public function delete_all()
|
|
|
{
|
|
|
+ // Make sure cache is inited
|
|
|
+ $this->_inited or $this->_init();
|
|
|
+
|
|
|
return $this->_delete_file($this->_cache_dir, TRUE);
|
|
|
}
|
|
|
|
|
@@ -282,6 +290,9 @@ class Kohana_Cache_File extends Cache implements Cache_GarbageCollect {
|
|
|
*/
|
|
|
public function garbage_collect()
|
|
|
{
|
|
|
+ // Make sure cache is inited
|
|
|
+ $this->_inited or $this->_init();
|
|
|
+
|
|
|
$this->_delete_file($this->_cache_dir, TRUE, FALSE, TRUE);
|
|
|
return;
|
|
|
}
|