summaryrefslogtreecommitdiffstats
path: root/system
diff options
context:
space:
mode:
authorAndrey Andreev <narf@bofh.bg>2011-12-25 18:23:50 +0100
committerAndrey Andreev <narf@bofh.bg>2011-12-25 18:23:50 +0100
commit7d4ea07ae5dee6abb0116e76ec9c9a876a02e610 (patch)
treed7c35540fd13a07aa12e4b40768d87790e631701 /system
parenta96ade374f28cdae97036fc253fd8b2a0e8dc81a (diff)
Improve the Cache library
Diffstat (limited to 'system')
-rw-r--r--system/libraries/Cache/Cache.php36
-rw-r--r--system/libraries/Cache/drivers/Cache_apc.php30
-rw-r--r--system/libraries/Cache/drivers/Cache_dummy.php8
-rw-r--r--system/libraries/Cache/drivers/Cache_file.php55
-rw-r--r--system/libraries/Cache/drivers/Cache_memcached.php10
5 files changed, 64 insertions, 75 deletions
diff --git a/system/libraries/Cache/Cache.php b/system/libraries/Cache/Cache.php
index c296fa770..87253739c 100644
--- a/system/libraries/Cache/Cache.php
+++ b/system/libraries/Cache/Cache.php
@@ -1,13 +1,13 @@
-<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
+<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
/**
* CodeIgniter
*
* An open source application development framework for PHP 5.1.6 or newer
*
* NOTICE OF LICENSE
- *
+ *
* Licensed under the Open Software License version 3.0
- *
+ *
* This source file is subject to the Open Software License (OSL 3.0) that is
* bundled with this package in the files license.txt / license.rst. It is
* also available through the world wide web at this URL:
@@ -22,22 +22,22 @@
* @license http://opensource.org/licenses/OSL-3.0 Open Software License (OSL 3.0)
* @link http://codeigniter.com
* @since Version 2.0
- * @filesource
+ * @filesource
*/
// ------------------------------------------------------------------------
/**
- * CodeIgniter Caching Class
+ * CodeIgniter Caching Class
*
* @package CodeIgniter
* @subpackage Libraries
* @category Core
* @author EllisLab Dev Team
- * @link
+ * @link
*/
class CI_Cache extends CI_Driver_Library {
-
+
protected $valid_drivers = array(
'cache_apc', 'cache_file', 'cache_memcached', 'cache_dummy'
);
@@ -45,7 +45,7 @@ class CI_Cache extends CI_Driver_Library {
protected $_cache_path = NULL; // Path of cache files (if file-based cache)
protected $_adapter = 'dummy';
protected $_backup_driver;
-
+
// ------------------------------------------------------------------------
/**
@@ -64,16 +64,16 @@ class CI_Cache extends CI_Driver_Library {
// ------------------------------------------------------------------------
/**
- * Get
+ * Get
*
- * Look for a value in the cache. If it exists, return the data
+ * Look for a value in the cache. If it exists, return the data
* if not, return FALSE
*
- * @param string
+ * @param string
* @return mixed value that is stored/FALSE on failure
*/
public function get($id)
- {
+ {
return $this->{$this->_adapter}->get($id);
}
@@ -124,7 +124,7 @@ class CI_Cache extends CI_Driver_Library {
* Cache Info
*
* @param string user/filehits
- * @return mixed array on success, false on failure
+ * @return mixed array on success, false on failure
*/
public function cache_info($type = 'user')
{
@@ -132,7 +132,7 @@ class CI_Cache extends CI_Driver_Library {
}
// ------------------------------------------------------------------------
-
+
/**
* Get Cache Metadata
*
@@ -143,7 +143,7 @@ class CI_Cache extends CI_Driver_Library {
{
return $this->{$this->_adapter}->get_metadata($id);
}
-
+
// ------------------------------------------------------------------------
/**
@@ -151,7 +151,7 @@ class CI_Cache extends CI_Driver_Library {
*
* Initialize class properties based on the configuration array.
*
- * @param array
+ * @param array
* @return void
*/
private function _initialize($config)
@@ -219,10 +219,10 @@ class CI_Cache extends CI_Driver_Library {
return $obj;
}
-
+
// ------------------------------------------------------------------------
}
// End Class
/* End of file Cache.php */
-/* Location: ./system/libraries/Cache/Cache.php */ \ No newline at end of file
+/* Location: ./system/libraries/Cache/Cache.php */
diff --git a/system/libraries/Cache/drivers/Cache_apc.php b/system/libraries/Cache/drivers/Cache_apc.php
index f15cf8501..90b68688d 100644
--- a/system/libraries/Cache/drivers/Cache_apc.php
+++ b/system/libraries/Cache/drivers/Cache_apc.php
@@ -1,13 +1,13 @@
-<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
+<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
/**
* CodeIgniter
*
* An open source application development framework for PHP 5.1.6 or newer
*
* NOTICE OF LICENSE
- *
+ *
* Licensed under the Open Software License version 3.0
- *
+ *
* This source file is subject to the Open Software License (OSL 3.0) that is
* bundled with this package in the files license.txt / license.rst. It is
* also available through the world wide web at this URL:
@@ -22,30 +22,30 @@
* @license http://opensource.org/licenses/OSL-3.0 Open Software License (OSL 3.0)
* @link http://codeigniter.com
* @since Version 2.0
- * @filesource
+ * @filesource
*/
// ------------------------------------------------------------------------
/**
- * CodeIgniter APC Caching Class
+ * CodeIgniter APC Caching Class
*
* @package CodeIgniter
* @subpackage Libraries
* @category Core
* @author EllisLab Dev Team
- * @link
+ * @link
*/
class CI_Cache_apc extends CI_Driver {
/**
- * Get
+ * Get
*
- * Look for a value in the cache. If it exists, return the data
+ * Look for a value in the cache. If it exists, return the data
* if not, return FALSE
*
- * @param string
+ * @param string
* @return mixed value that is stored/FALSE on failure
*/
public function get($id)
@@ -55,8 +55,8 @@ class CI_Cache_apc extends CI_Driver {
return (is_array($data)) ? $data[0] : FALSE;
}
- // ------------------------------------------------------------------------
-
+ // ------------------------------------------------------------------------
+
/**
* Cache Save
*
@@ -70,7 +70,7 @@ class CI_Cache_apc extends CI_Driver {
{
return apc_store($id, array($data, time(), $ttl), $ttl);
}
-
+
// ------------------------------------------------------------------------
/**
@@ -102,7 +102,7 @@ class CI_Cache_apc extends CI_Driver {
* Cache Info
*
* @param string user/filehits
- * @return mixed array on success, false on failure
+ * @return mixed array on success, false on failure
*/
public function cache_info($type = NULL)
{
@@ -149,13 +149,13 @@ class CI_Cache_apc extends CI_Driver {
log_message('error', 'The APC PHP extension must be loaded to use APC Cache.');
return FALSE;
}
-
+
return TRUE;
}
// ------------------------------------------------------------------------
-
+
}
// End Class
diff --git a/system/libraries/Cache/drivers/Cache_dummy.php b/system/libraries/Cache/drivers/Cache_dummy.php
index 965bb2bef..ff787e90b 100644
--- a/system/libraries/Cache/drivers/Cache_dummy.php
+++ b/system/libraries/Cache/drivers/Cache_dummy.php
@@ -1,13 +1,13 @@
-<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
+<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
/**
* CodeIgniter
*
* An open source application development framework for PHP 5.1.6 or newer
*
* NOTICE OF LICENSE
- *
+ *
* Licensed under the Open Software License version 3.0
- *
+ *
* This source file is subject to the Open Software License (OSL 3.0) that is
* bundled with this package in the files license.txt / license.rst. It is
* also available through the world wide web at this URL:
@@ -138,4 +138,4 @@ class CI_Cache_dummy extends CI_Driver {
// End Class
/* End of file Cache_dummy.php */
-/* Location: ./system/libraries/Cache/drivers/Cache_dummy.php */ \ No newline at end of file
+/* Location: ./system/libraries/Cache/drivers/Cache_dummy.php */
diff --git a/system/libraries/Cache/drivers/Cache_file.php b/system/libraries/Cache/drivers/Cache_file.php
index be392d3d2..194279726 100644
--- a/system/libraries/Cache/drivers/Cache_file.php
+++ b/system/libraries/Cache/drivers/Cache_file.php
@@ -1,13 +1,13 @@
-<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
+<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
/**
* CodeIgniter
*
* An open source application development framework for PHP 5.1.6 or newer
*
* NOTICE OF LICENSE
- *
+ *
* Licensed under the Open Software License version 3.0
- *
+ *
* This source file is subject to the Open Software License (OSL 3.0) that is
* bundled with this package in the files license.txt / license.rst. It is
* also available through the world wide web at this URL:
@@ -22,19 +22,19 @@
* @license http://opensource.org/licenses/OSL-3.0 Open Software License (OSL 3.0)
* @link http://codeigniter.com
* @since Version 2.0
- * @filesource
+ * @filesource
*/
// ------------------------------------------------------------------------
/**
- * CodeIgniter Memcached Caching Class
+ * CodeIgniter Memcached Caching Class
*
* @package CodeIgniter
* @subpackage Libraries
* @category Core
* @author EllisLab Dev Team
- * @link
+ * @link
*/
class CI_Cache_file extends CI_Driver {
@@ -48,9 +48,7 @@ class CI_Cache_file extends CI_Driver {
{
$CI =& get_instance();
$CI->load->helper('file');
-
$path = $CI->config->item('cache_path');
-
$this->_cache_path = ($path == '') ? APPPATH.'cache/' : $path;
}
@@ -68,16 +66,15 @@ class CI_Cache_file extends CI_Driver {
{
return FALSE;
}
-
- $data = read_file($this->_cache_path.$id);
- $data = unserialize($data);
-
+
+ $data = unserialize(read_file($this->_cache_path.$id));
+
if (time() > $data['time'] + $data['ttl'])
{
unlink($this->_cache_path.$id);
return FALSE;
}
-
+
return $data['data'];
}
@@ -88,22 +85,22 @@ class CI_Cache_file extends CI_Driver {
*
* @param string unique key
* @param mixed data to store
- * @param int length of time (in seconds) the cache is valid
+ * @param int length of time (in seconds) the cache is valid
* - Default is 60 seconds
* @return boolean true on success/false on failure
*/
public function save($id, $data, $ttl = 60)
- {
+ {
$contents = array(
'time' => time(),
- 'ttl' => $ttl,
+ 'ttl' => $ttl,
'data' => $data
);
-
+
if (write_file($this->_cache_path.$id, serialize($contents)))
{
@chmod($this->_cache_path.$id, 0777);
- return TRUE;
+ return TRUE;
}
return FALSE;
@@ -119,14 +116,7 @@ class CI_Cache_file extends CI_Driver {
*/
public function delete($id)
{
- if (file_exists($this->_cache_path.$id))
- {
- return unlink($this->_cache_path.$id);
- }
- else
- {
- return FALSE;
- }
+ return (file_exists($this->_cache_path.$id)) ? unlink($this->_cache_path.$id) : FALSE;
}
// ------------------------------------------------------------------------
@@ -135,7 +125,7 @@ class CI_Cache_file extends CI_Driver {
* Clean the Cache
*
* @return boolean false on failure/true on success
- */
+ */
public function clean()
{
return delete_files($this->_cache_path);
@@ -170,10 +160,9 @@ class CI_Cache_file extends CI_Driver {
{
return FALSE;
}
-
- $data = read_file($this->_cache_path.$id);
- $data = unserialize($data);
-
+
+ $data = unserialize(read_file($this->_cache_path.$id));
+
if (is_array($data))
{
$mtime = filemtime($this->_cache_path.$id);
@@ -188,7 +177,7 @@ class CI_Cache_file extends CI_Driver {
'mtime' => $mtime
);
}
-
+
return FALSE;
}
@@ -198,7 +187,7 @@ class CI_Cache_file extends CI_Driver {
* Is supported
*
* In the file driver, check to see that the cache directory is indeed writable
- *
+ *
* @return boolean
*/
public function is_supported()
diff --git a/system/libraries/Cache/drivers/Cache_memcached.php b/system/libraries/Cache/drivers/Cache_memcached.php
index 78cab25d4..0037e6755 100644
--- a/system/libraries/Cache/drivers/Cache_memcached.php
+++ b/system/libraries/Cache/drivers/Cache_memcached.php
@@ -1,13 +1,13 @@
-<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
+<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
/**
* CodeIgniter
*
* An open source application development framework for PHP 5.1.6 or newer
*
* NOTICE OF LICENSE
- *
+ *
* Licensed under the Open Software License version 3.0
- *
+ *
* This source file is subject to the Open Software License (OSL 3.0) that is
* bundled with this package in the files license.txt / license.rst. It is
* also available through the world wide web at this URL:
@@ -84,7 +84,7 @@ class CI_Cache_memcached extends CI_Driver {
{
return $this->_memcached->set($id, array($data, time(), $ttl), 0, $ttl);
}
-
+
return FALSE;
}
@@ -256,4 +256,4 @@ class CI_Cache_memcached extends CI_Driver {
// End Class
/* End of file Cache_memcached.php */
-/* Location: ./system/libraries/Cache/drivers/Cache_memcached.php */ \ No newline at end of file
+/* Location: ./system/libraries/Cache/drivers/Cache_memcached.php */