summaryrefslogtreecommitdiffstats
path: root/system/libraries/Cache
diff options
context:
space:
mode:
authorAnton Lindqvist <anton@qvister.se>2012-04-25 12:08:37 +0200
committerAnton Lindqvist <anton@qvister.se>2012-04-25 12:08:37 +0200
commit92f10e837d132f9866626d3f2e0a633b22329ebb (patch)
treee3ade8c7dd46f90690455fb2dcc112d6d015c980 /system/libraries/Cache
parent210e664abe857ddd267a7ba8713e2318d3e59a9c (diff)
parentf8ae11598ba058ee02cc4f8c82dbab3420756aae (diff)
Merge branch 'develop' of https://github.com/EllisLab/CodeIgniter into develop
Conflicts: system/libraries/Cache/Cache.php
Diffstat (limited to 'system/libraries/Cache')
-rw-r--r--system/libraries/Cache/Cache.php121
-rw-r--r--system/libraries/Cache/drivers/Cache_apc.php45
-rw-r--r--system/libraries/Cache/drivers/Cache_dummy.php39
-rw-r--r--system/libraries/Cache/drivers/Cache_file.php46
-rw-r--r--system/libraries/Cache/drivers/Cache_memcached.php65
-rw-r--r--system/libraries/Cache/drivers/Cache_wincache.php162
6 files changed, 298 insertions, 180 deletions
diff --git a/system/libraries/Cache/Cache.php b/system/libraries/Cache/Cache.php
index 25555506c..16d83432b 100644
--- a/system/libraries/Cache/Cache.php
+++ b/system/libraries/Cache/Cache.php
@@ -2,7 +2,7 @@
/**
* CodeIgniter
*
- * An open source application development framework for PHP 5.1.6 or newer
+ * An open source application development framework for PHP 5.2.4 or newer
*
* NOTICE OF LICENSE
*
@@ -25,8 +25,6 @@
* @filesource
*/
-// ------------------------------------------------------------------------
-
/**
* CodeIgniter Caching Class
*
@@ -39,25 +37,49 @@
class CI_Cache extends CI_Driver_Library {
protected $valid_drivers = array(
- 'cache_apc', 'cache_file', 'cache_memcached', 'cache_redis', 'cache_dummy'
- );
-
- protected $_cache_path = NULL; // Path of cache files (if file-based cache)
+ 'cache_apc',
+ 'cache_file',
+ 'cache_memcached',
+ 'cache_dummy',
+ 'cache_wincache',
+ 'cache_redis'
+ );
+
+ protected $_cache_path = NULL; // Path of cache files (if file-based cache)
protected $_adapter = 'dummy';
protected $_backup_driver;
- // ------------------------------------------------------------------------
-
/**
* Constructor
*
- * @param array
+ * Initialize class properties based on the configuration array.
+ *
+ * @param array
+ * @return void
*/
public function __construct($config = array())
{
- if ( ! empty($config))
+ $default_config = array(
+ 'adapter',
+ 'memcached'
+ );
+
+ foreach ($default_config as $key)
{
- $this->_initialize($config);
+ if (isset($config[$key]))
+ {
+ $param = '_'.$key;
+
+ $this->{$param} = $config[$key];
+ }
+ }
+
+ if (isset($config['backup']))
+ {
+ if (in_array('cache_'.$config['backup'], $this->valid_drivers))
+ {
+ $this->_backup_driver = $config['backup'];
+ }
}
}
@@ -66,11 +88,11 @@ class CI_Cache extends CI_Driver_Library {
/**
* 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
- * @return mixed value that is stored/FALSE on failure
+ * @param string
+ * @return mixed value that is stored/FALSE on failure
*/
public function get($id)
{
@@ -82,11 +104,10 @@ class CI_Cache extends CI_Driver_Library {
/**
* Cache Save
*
- * @param string Unique Key
- * @param mixed Data to store
- * @param int Length of time (in seconds) to cache the data
- *
- * @return boolean true on success/false on failure
+ * @param string Unique Key
+ * @param mixed Data to store
+ * @param int Length of time (in seconds) to cache the data
+ * @return bool true on success/false on failure
*/
public function save($id, $data, $ttl = 60)
{
@@ -98,8 +119,8 @@ class CI_Cache extends CI_Driver_Library {
/**
* Delete from Cache
*
- * @param mixed unique identifier of the item in the cache
- * @return boolean true on success/false on failure
+ * @param mixed unique identifier of the item in the cache
+ * @return bool true on success/false on failure
*/
public function delete($id)
{
@@ -111,7 +132,7 @@ class CI_Cache extends CI_Driver_Library {
/**
* Clean the cache
*
- * @return boolean false on failure/true on success
+ * @return bool false on failure/true on success
*/
public function clean()
{
@@ -123,8 +144,8 @@ class CI_Cache extends CI_Driver_Library {
/**
* Cache Info
*
- * @param string user/filehits
- * @return mixed array on success, false on failure
+ * @param string user/filehits
+ * @return mixed array on success, false on failure
*/
public function cache_info($type = 'user')
{
@@ -136,8 +157,8 @@ class CI_Cache extends CI_Driver_Library {
/**
* Get Cache Metadata
*
- * @param mixed key to get cache metadata on
- * @return mixed return value from child method
+ * @param mixed key to get cache metadata on
+ * @return mixed return value from child method
*/
public function get_metadata($id)
{
@@ -147,46 +168,10 @@ class CI_Cache extends CI_Driver_Library {
// ------------------------------------------------------------------------
/**
- * Initialize
- *
- * Initialize class properties based on the configuration array.
- *
- * @param array
- * @return void
- */
- private function _initialize($config)
- {
- $default_config = array(
- 'adapter',
- 'memcached'
- );
-
- foreach ($default_config as $key)
- {
- if (isset($config[$key]))
- {
- $param = '_'.$key;
-
- $this->{$param} = $config[$key];
- }
- }
-
- if (isset($config['backup']))
- {
- if (in_array('cache_'.$config['backup'], $this->valid_drivers))
- {
- $this->_backup_driver = $config['backup'];
- }
- }
- }
-
- // ------------------------------------------------------------------------
-
- /**
* Is the requested driver supported in this environment?
*
- * @param string The driver to test.
- * @return array
+ * @param string The driver to test.
+ * @return array
*/
public function is_supported($driver)
{
@@ -205,8 +190,8 @@ class CI_Cache extends CI_Driver_Library {
/**
* __get()
*
- * @param child
- * @return object
+ * @param child
+ * @return object
*/
public function __get($child)
{
@@ -220,9 +205,7 @@ class CI_Cache extends CI_Driver_Library {
return $obj;
}
- // ------------------------------------------------------------------------
}
-// End Class
/* End of file Cache.php */
/* 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 a3dd46978..59ab67533 100644
--- a/system/libraries/Cache/drivers/Cache_apc.php
+++ b/system/libraries/Cache/drivers/Cache_apc.php
@@ -2,7 +2,7 @@
/**
* CodeIgniter
*
- * An open source application development framework for PHP 5.1.6 or newer
+ * An open source application development framework for PHP 5.2.4 or newer
*
* NOTICE OF LICENSE
*
@@ -25,8 +25,6 @@
* @filesource
*/
-// ------------------------------------------------------------------------
-
/**
* CodeIgniter APC Caching Class
*
@@ -36,23 +34,22 @@
* @author EllisLab Dev Team
* @link
*/
-
class CI_Cache_apc extends CI_Driver {
/**
* 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
- * @return mixed value that is stored/FALSE on failure
+ * @param string
+ * @return mixed value that is stored/FALSE on failure
*/
public function get($id)
{
$data = apc_fetch($id);
- return (is_array($data)) ? $data[0] : FALSE;
+ return is_array($data) ? $data[0] : FALSE;
}
// ------------------------------------------------------------------------
@@ -60,11 +57,11 @@ class CI_Cache_apc extends CI_Driver {
/**
* Cache Save
*
- * @param string Unique Key
- * @param mixed Data to store
- * @param int Length of time (in seconds) to cache the data
+ * @param string Unique Key
+ * @param mixed Data to store
+ * @param int Length of time (in seconds) to cache the data
*
- * @return boolean true on success/false on failure
+ * @return bool true on success/false on failure
*/
public function save($id, $data, $ttl = 60)
{
@@ -77,8 +74,8 @@ class CI_Cache_apc extends CI_Driver {
/**
* Delete from Cache
*
- * @param mixed unique identifier of the item in the cache
- * @param boolean true on success/false on failure
+ * @param mixed unique identifier of the item in the cache
+ * @param bool true on success/false on failure
*/
public function delete($id)
{
@@ -90,7 +87,7 @@ class CI_Cache_apc extends CI_Driver {
/**
* Clean the cache
*
- * @return boolean false on failure/true on success
+ * @return bool false on failure/true on success
*/
public function clean()
{
@@ -102,8 +99,8 @@ class CI_Cache_apc extends CI_Driver {
/**
* Cache Info
*
- * @param string user/filehits
- * @return mixed array on success, false on failure
+ * @param string user/filehits
+ * @return mixed array on success, false on failure
*/
public function cache_info($type = NULL)
{
@@ -115,8 +112,8 @@ class CI_Cache_apc extends CI_Driver {
/**
* Get Cache Metadata
*
- * @param mixed key to get cache metadata on
- * @return mixed array on success/false on failure
+ * @param mixed key to get cache metadata on
+ * @return mixed array on success/false on failure
*/
public function get_metadata($id)
{
@@ -142,10 +139,12 @@ class CI_Cache_apc extends CI_Driver {
* is_supported()
*
* Check to see if APC is available on this system, bail if it isn't.
+ *
+ * @return bool
*/
public function is_supported()
{
- if ( ! extension_loaded('apc') OR ini_get('apc.enabled') != "1")
+ if ( ! extension_loaded('apc') OR ! (bool) @ini_get('apc.enabled'))
{
log_message('error', 'The APC PHP extension must be loaded to use APC Cache.');
return FALSE;
@@ -154,11 +153,7 @@ class CI_Cache_apc extends CI_Driver {
return TRUE;
}
- // ------------------------------------------------------------------------
-
-
}
-// End Class
/* End of file Cache_apc.php */
-/* Location: ./system/libraries/Cache/drivers/Cache_apc.php */
+/* Location: ./system/libraries/Cache/drivers/Cache_apc.php */ \ No newline at end of file
diff --git a/system/libraries/Cache/drivers/Cache_dummy.php b/system/libraries/Cache/drivers/Cache_dummy.php
index fcd55da39..e8b791c5b 100644
--- a/system/libraries/Cache/drivers/Cache_dummy.php
+++ b/system/libraries/Cache/drivers/Cache_dummy.php
@@ -2,7 +2,7 @@
/**
* CodeIgniter
*
- * An open source application development framework for PHP 5.1.6 or newer
+ * An open source application development framework for PHP 5.2.4 or newer
*
* NOTICE OF LICENSE
*
@@ -25,8 +25,6 @@
* @filesource
*/
-// ------------------------------------------------------------------------
-
/**
* CodeIgniter Dummy Caching Class
*
@@ -36,7 +34,6 @@
* @author EllisLab Dev Team
* @link
*/
-
class CI_Cache_dummy extends CI_Driver {
/**
@@ -44,8 +41,8 @@ class CI_Cache_dummy extends CI_Driver {
*
* Since this is the dummy class, it's always going to return FALSE.
*
- * @param string
- * @return Boolean FALSE
+ * @param string
+ * @return bool FALSE
*/
public function get($id)
{
@@ -57,11 +54,10 @@ class CI_Cache_dummy extends CI_Driver {
/**
* Cache Save
*
- * @param string Unique Key
- * @param mixed Data to store
- * @param int Length of time (in seconds) to cache the data
- *
- * @return boolean TRUE, Simulating success
+ * @param string Unique Key
+ * @param mixed Data to store
+ * @param int Length of time (in seconds) to cache the data
+ * @return bool TRUE, Simulating success
*/
public function save($id, $data, $ttl = 60)
{
@@ -73,8 +69,8 @@ class CI_Cache_dummy extends CI_Driver {
/**
* Delete from Cache
*
- * @param mixed unique identifier of the item in the cache
- * @param boolean TRUE, simulating success
+ * @param mixed unique identifier of the item in the cache
+ * @param bool TRUE, simulating success
*/
public function delete($id)
{
@@ -86,7 +82,7 @@ class CI_Cache_dummy extends CI_Driver {
/**
* Clean the cache
*
- * @return boolean TRUE, simulating success
+ * @return bool TRUE, simulating success
*/
public function clean()
{
@@ -98,8 +94,8 @@ class CI_Cache_dummy extends CI_Driver {
/**
* Cache Info
*
- * @param string user/filehits
- * @return boolean FALSE
+ * @param string user/filehits
+ * @return bool FALSE
*/
public function cache_info($type = NULL)
{
@@ -111,8 +107,8 @@ class CI_Cache_dummy extends CI_Driver {
/**
* Get Cache Metadata
*
- * @param mixed key to get cache metadata on
- * @return boolean FALSE
+ * @param mixed key to get cache metadata on
+ * @return bool FALSE
*/
public function get_metadata($id)
{
@@ -125,17 +121,14 @@ class CI_Cache_dummy extends CI_Driver {
* Is this caching driver supported on the system?
* Of course this one is.
*
- * @return TRUE;
+ * @return bool TRUE
*/
public function is_supported()
{
return TRUE;
}
- // ------------------------------------------------------------------------
-
}
-// End Class
/* End of file Cache_dummy.php */
-/* Location: ./system/libraries/Cache/drivers/Cache_dummy.php */
+/* Location: ./system/libraries/Cache/drivers/Cache_dummy.php */ \ No newline at end of file
diff --git a/system/libraries/Cache/drivers/Cache_file.php b/system/libraries/Cache/drivers/Cache_file.php
index 4a81b0422..dd27aa90e 100644
--- a/system/libraries/Cache/drivers/Cache_file.php
+++ b/system/libraries/Cache/drivers/Cache_file.php
@@ -2,7 +2,7 @@
/**
* CodeIgniter
*
- * An open source application development framework for PHP 5.1.6 or newer
+ * An open source application development framework for PHP 5.2.4 or newer
*
* NOTICE OF LICENSE
*
@@ -25,8 +25,6 @@
* @filesource
*/
-// ------------------------------------------------------------------------
-
/**
* CodeIgniter Memcached Caching Class
*
@@ -36,14 +34,10 @@
* @author EllisLab Dev Team
* @link
*/
-
class CI_Cache_file extends CI_Driver {
protected $_cache_path;
- /**
- * Constructor
- */
public function __construct()
{
$CI =& get_instance();
@@ -57,8 +51,8 @@ class CI_Cache_file extends CI_Driver {
/**
* Fetch from cache
*
- * @param mixed unique key id
- * @return mixed data on success/false on failure
+ * @param mixed unique key id
+ * @return mixed data on success/false on failure
*/
public function get($id)
{
@@ -83,11 +77,11 @@ class CI_Cache_file extends CI_Driver {
/**
* Save into cache
*
- * @param string unique key
- * @param mixed data to store
- * @param int length of time (in seconds) the cache is valid
- * - Default is 60 seconds
- * @return boolean true on success/false on failure
+ * @param string unique key
+ * @param mixed data to store
+ * @param int length of time (in seconds) the cache is valid
+ * - Default is 60 seconds
+ * @return bool true on success/false on failure
*/
public function save($id, $data, $ttl = 60)
{
@@ -99,7 +93,7 @@ class CI_Cache_file extends CI_Driver {
if (write_file($this->_cache_path.$id, serialize($contents)))
{
- @chmod($this->_cache_path.$id, 0777);
+ @chmod($this->_cache_path.$id, 0660);
return TRUE;
}
@@ -111,12 +105,12 @@ class CI_Cache_file extends CI_Driver {
/**
* Delete from Cache
*
- * @param mixed unique identifier of item in cache
- * @return boolean true on success/false on failure
+ * @param mixed unique identifier of item in cache
+ * @return bool true on success/false on failure
*/
public function delete($id)
{
- return (file_exists($this->_cache_path.$id)) ? unlink($this->_cache_path.$id) : FALSE;
+ return file_exists($this->_cache_path.$id) ? unlink($this->_cache_path.$id) : FALSE;
}
// ------------------------------------------------------------------------
@@ -124,7 +118,7 @@ class CI_Cache_file extends CI_Driver {
/**
* Clean the Cache
*
- * @return boolean false on failure/true on success
+ * @return bool false on failure/true on success
*/
public function clean()
{
@@ -138,8 +132,8 @@ class CI_Cache_file extends CI_Driver {
*
* Not supported by file-based caching
*
- * @param string user/filehits
- * @return mixed FALSE
+ * @param string user/filehits
+ * @return mixed FALSE
*/
public function cache_info($type = NULL)
{
@@ -151,8 +145,8 @@ class CI_Cache_file extends CI_Driver {
/**
* Get Cache Metadata
*
- * @param mixed key to get cache metadata on
- * @return mixed FALSE on failure, array on success.
+ * @param mixed key to get cache metadata on
+ * @return mixed FALSE on failure, array on success.
*/
public function get_metadata($id)
{
@@ -188,16 +182,14 @@ class CI_Cache_file extends CI_Driver {
*
* In the file driver, check to see that the cache directory is indeed writable
*
- * @return boolean
+ * @return bool
*/
public function is_supported()
{
return is_really_writable($this->_cache_path);
}
- // ------------------------------------------------------------------------
}
-// End Class
/* End of file Cache_file.php */
-/* Location: ./system/libraries/Cache/drivers/Cache_file.php */
+/* Location: ./system/libraries/Cache/drivers/Cache_file.php */ \ No newline at end of file
diff --git a/system/libraries/Cache/drivers/Cache_memcached.php b/system/libraries/Cache/drivers/Cache_memcached.php
index ffe6f2ff7..4cd5f3d6f 100644
--- a/system/libraries/Cache/drivers/Cache_memcached.php
+++ b/system/libraries/Cache/drivers/Cache_memcached.php
@@ -2,7 +2,7 @@
/**
* CodeIgniter
*
- * An open source application development framework for PHP 5.1.6 or newer
+ * An open source application development framework for PHP 5.2.4 or newer
*
* NOTICE OF LICENSE
*
@@ -25,8 +25,6 @@
* @filesource
*/
-// ------------------------------------------------------------------------
-
/**
* CodeIgniter Memcached Caching Class
*
@@ -36,12 +34,11 @@
* @author EllisLab Dev Team
* @link
*/
-
class CI_Cache_memcached extends CI_Driver {
- private $_memcached; // Holds the memcached object
+ protected $_memcached; // Holds the memcached object
- protected $_memcache_conf = array(
+ protected $_memcache_conf = array(
'default' => array(
'default_host' => '127.0.0.1',
'default_port' => 11211,
@@ -49,19 +46,17 @@ class CI_Cache_memcached extends CI_Driver {
)
);
- // ------------------------------------------------------------------------
-
/**
* Fetch from cache
*
- * @param mixed unique key id
- * @return mixed data on success/false on failure
+ * @param mixed unique key id
+ * @return mixed data on success/false on failure
*/
public function get($id)
{
$data = $this->_memcached->get($id);
- return (is_array($data)) ? $data[0] : FALSE;
+ return is_array($data) ? $data[0] : FALSE;
}
// ------------------------------------------------------------------------
@@ -69,18 +64,18 @@ class CI_Cache_memcached extends CI_Driver {
/**
* Save
*
- * @param string unique identifier
- * @param mixed data being cached
- * @param int time to live
- * @return boolean true on success, false on failure
+ * @param string unique identifier
+ * @param mixed data being cached
+ * @param int time to live
+ * @return bool true on success, false on failure
*/
public function save($id, $data, $ttl = 60)
{
- if (get_class($this->_memcached) == 'Memcached')
+ if (get_class($this->_memcached) === 'Memcached')
{
return $this->_memcached->set($id, array($data, time(), $ttl), $ttl);
}
- else if (get_class($this->_memcached) == 'Memcache')
+ elseif (get_class($this->_memcached) === 'Memcache')
{
return $this->_memcached->set($id, array($data, time(), $ttl), 0, $ttl);
}
@@ -93,8 +88,8 @@ class CI_Cache_memcached extends CI_Driver {
/**
* Delete from Cache
*
- * @param mixed key to be deleted.
- * @return boolean true on success, false on failure
+ * @param mixed key to be deleted.
+ * @return bool true on success, false on failure
*/
public function delete($id)
{
@@ -106,7 +101,7 @@ class CI_Cache_memcached extends CI_Driver {
/**
* Clean the Cache
*
- * @return boolean false on failure/true on success
+ * @return bool false on failure/true on success
*/
public function clean()
{
@@ -118,10 +113,9 @@ class CI_Cache_memcached extends CI_Driver {
/**
* Cache Info
*
- * @param null type not supported in memcached
- * @return mixed array on success, false on failure
+ * @return mixed array on success, false on failure
*/
- public function cache_info($type = NULL)
+ public function cache_info()
{
return $this->_memcached->getStats();
}
@@ -131,8 +125,8 @@ class CI_Cache_memcached extends CI_Driver {
/**
* Get Cache Metadata
*
- * @param mixed key to get cache metadata on
- * @return mixed FALSE on failure, array on success.
+ * @param mixed key to get cache metadata on
+ * @return mixed FALSE on failure, array on success.
*/
public function get_metadata($id)
{
@@ -156,8 +150,10 @@ class CI_Cache_memcached extends CI_Driver {
/**
* Setup memcached.
+ *
+ * @return bool
*/
- private function _setup_memcached()
+ protected function _setup_memcached()
{
// Try to load memcached server info from the config file.
$CI =& get_instance();
@@ -179,14 +175,13 @@ class CI_Cache_memcached extends CI_Driver {
{
$this->_memcached = new Memcached();
}
- else if (class_exists('Memcache'))
+ elseif (class_exists('Memcache'))
{
$this->_memcached = new Memcache();
}
else
{
log_message('error', 'Failed to create object for Memcached Cache; extension not loaded?');
-
return FALSE;
}
@@ -194,17 +189,17 @@ class CI_Cache_memcached extends CI_Driver {
{
if ( ! array_key_exists('hostname', $cache_server))
{
- $cache_server['hostname'] = $this->_default_options['default_host'];
+ $cache_server['hostname'] = $this->_memcache_conf['default']['default_host'];
}
if ( ! array_key_exists('port', $cache_server))
{
- $cache_server['port'] = $this->_default_options['default_port'];
+ $cache_server['port'] = $this->_memcache_conf['default']['default_port'];
}
if ( ! array_key_exists('weight', $cache_server))
{
- $cache_server['weight'] = $this->_default_options['default_weight'];
+ $cache_server['weight'] = $this->_memcache_conf['default']['default_weight'];
}
if (get_class($this->_memcached) == 'Memcache')
@@ -237,23 +232,21 @@ class CI_Cache_memcached extends CI_Driver {
*
* Returns FALSE if memcached is not supported on the system.
* If it is, we setup the memcached object & return TRUE
+ *
+ * @return bool
*/
public function is_supported()
{
if ( ! extension_loaded('memcached') && ! extension_loaded('memcache'))
{
log_message('error', 'The Memcached Extension must be loaded to use Memcached Cache.');
-
return FALSE;
}
return $this->_setup_memcached();
}
- // ------------------------------------------------------------------------
-
}
-// End Class
/* End of file Cache_memcached.php */
-/* Location: ./system/libraries/Cache/drivers/Cache_memcached.php */
+/* Location: ./system/libraries/Cache/drivers/Cache_memcached.php */ \ No newline at end of file
diff --git a/system/libraries/Cache/drivers/Cache_wincache.php b/system/libraries/Cache/drivers/Cache_wincache.php
new file mode 100644
index 000000000..b32e66a46
--- /dev/null
+++ b/system/libraries/Cache/drivers/Cache_wincache.php
@@ -0,0 +1,162 @@
+<?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:
+ * http://opensource.org/licenses/OSL-3.0
+ * If you did not receive a copy of the license and are unable to obtain it
+ * through the world wide web, please send an email to
+ * licensing@ellislab.com so we can send you a copy immediately.
+ *
+ * @package CodeIgniter
+ * @author EllisLab Dev Team
+ * @copyright Copyright (c) 2006 - 2012 EllisLab, Inc.
+ * @license http://opensource.org/licenses/OSL-3.0 Open Software License (OSL 3.0)
+ * @link http://codeigniter.com
+ * @since Version 3.0
+ * @filesource
+ */
+
+/**
+ * CodeIgniter Wincache Caching Class
+ *
+ * Read more about Wincache functions here:
+ * http://www.php.net/manual/en/ref.wincache.php
+ *
+ * @package CodeIgniter
+ * @subpackage Libraries
+ * @category Core
+ * @author Mike Murkovic
+ * @link
+ */
+class CI_Cache_wincache extends CI_Driver {
+
+ /**
+ * Get
+ *
+ * Look for a value in the cache. If it exists, return the data,
+ * if not, return FALSE
+ *
+ * @param string
+ * @return mixed value that is stored/FALSE on failure
+ */
+ public function get($id)
+ {
+ $success = FALSE;
+ $data = wincache_ucache_get($id, $success);
+
+ // Success returned by reference from wincache_ucache_get()
+ return ($success) ? $data : FALSE;
+ }
+
+ // ------------------------------------------------------------------------
+
+ /**
+ * Cache Save
+ *
+ * @param string Unique Key
+ * @param mixed Data to store
+ * @param int Length of time (in seconds) to cache the data
+ * @return bool true on success/false on failure
+ */
+ public function save($id, $data, $ttl = 60)
+ {
+ return wincache_ucache_set($id, $data, $ttl);
+ }
+
+ // ------------------------------------------------------------------------
+
+ /**
+ * Delete from Cache
+ *
+ * @param mixed unique identifier of the item in the cache
+ * @param bool true on success/false on failure
+ */
+ public function delete($id)
+ {
+ return wincache_ucache_delete($id);
+ }
+
+ // ------------------------------------------------------------------------
+
+ /**
+ * Clean the cache
+ *
+ * @return bool false on failure/true on success
+ */
+ public function clean()
+ {
+ return wincache_ucache_clear();
+ }
+
+ // ------------------------------------------------------------------------
+
+ /**
+ * Cache Info
+ *
+ * @return mixed array on success, false on failure
+ */
+ public function cache_info()
+ {
+ return wincache_ucache_info(TRUE);
+ }
+
+ // ------------------------------------------------------------------------
+
+ /**
+ * Get Cache Metadata
+ *
+ * @param mixed key to get cache metadata on
+ * @return mixed array on success/false on failure
+ */
+ public function get_metadata($id)
+ {
+ if ($stored = wincache_ucache_info(FALSE, $id))
+ {
+ $age = $stored['ucache_entries'][1]['age_seconds'];
+ $ttl = $stored['ucache_entries'][1]['ttl_seconds'];
+ $hitcount = $stored['ucache_entries'][1]['hitcount'];
+
+ return array(
+ 'expire' => $ttl - $age,
+ 'hitcount' => $hitcount,
+ 'age' => $age,
+ 'ttl' => $ttl
+ );
+ }
+
+ return FALSE;
+ }
+
+ // ------------------------------------------------------------------------
+
+ /**
+ * is_supported()
+ *
+ * Check to see if WinCache is available on this system, bail if it isn't.
+ *
+ * @return bool
+ */
+ public function is_supported()
+ {
+ if ( ! extension_loaded('wincache'))
+ {
+ log_message('error', 'The Wincache PHP extension must be loaded to use Wincache Cache.');
+ return FALSE;
+ }
+
+ return TRUE;
+ }
+
+}
+
+/* End of file Cache_wincache.php */
+/* Location: ./system/libraries/Cache/drivers/Cache_wincache.php */ \ No newline at end of file