From c26f4d057fc9c028cfa7575399e04cfdd544f04e Mon Sep 17 00:00:00 2001 From: katsew Date: Mon, 20 Feb 2017 14:07:44 +0900 Subject: Create Cache_apcu class and copy source from Cache_apc class Signed-off-by: katsew --- system/libraries/Cache/drivers/Cache_apcu.php | 221 ++++++++++++++++++++++++++ 1 file changed, 221 insertions(+) create mode 100644 system/libraries/Cache/drivers/Cache_apcu.php (limited to 'system/libraries') diff --git a/system/libraries/Cache/drivers/Cache_apcu.php b/system/libraries/Cache/drivers/Cache_apcu.php new file mode 100644 index 000000000..066fe428f --- /dev/null +++ b/system/libraries/Cache/drivers/Cache_apcu.php @@ -0,0 +1,221 @@ +is_supported()) + { + log_message('error', 'Cache: Failed to initialize APC; extension not loaded/enabled?'); + } + } + + // ------------------------------------------------------------------------ + + /** + * 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 = apc_fetch($id, $success); + + if ($success === TRUE) + { + return is_array($data) + ? unserialize($data[0]) + : $data; + } + + return FALSE; + } + + // ------------------------------------------------------------------------ + + /** + * Cache Save + * + * @param string $id Cache ID + * @param mixed $data Data to store + * @param int $ttl Length of time (in seconds) to cache the data + * @param bool $raw Whether to store the raw value + * @return bool TRUE on success, FALSE on failure + */ + public function save($id, $data, $ttl = 60, $raw = FALSE) + { + $ttl = (int) $ttl; + + return apc_store( + $id, + ($raw === TRUE ? $data : array(serialize($data), time(), $ttl)), + $ttl + ); + } + + // ------------------------------------------------------------------------ + + /** + * Delete from Cache + * + * @param mixed unique identifier of the item in the cache + * @return bool true on success/false on failure + */ + public function delete($id) + { + return apc_delete($id); + } + + // ------------------------------------------------------------------------ + + /** + * Increment a raw value + * + * @param string $id Cache ID + * @param int $offset Step/value to add + * @return mixed New value on success or FALSE on failure + */ + public function increment($id, $offset = 1) + { + return apc_inc($id, $offset); + } + + // ------------------------------------------------------------------------ + + /** + * Decrement a raw value + * + * @param string $id Cache ID + * @param int $offset Step/value to reduce by + * @return mixed New value on success or FALSE on failure + */ + public function decrement($id, $offset = 1) + { + return apc_dec($id, $offset); + } + + // ------------------------------------------------------------------------ + + /** + * Clean the cache + * + * @return bool false on failure/true on success + */ + public function clean() + { + return apc_clear_cache('user'); + } + + // ------------------------------------------------------------------------ + + /** + * Cache Info + * + * @param string user/filehits + * @return mixed array on success, false on failure + */ + public function cache_info($type = NULL) + { + return apc_cache_info($type); + } + + // ------------------------------------------------------------------------ + + /** + * Get Cache Metadata + * + * @param mixed key to get cache metadata on + * @return mixed array on success/false on failure + */ + public function get_metadata($id) + { + $success = FALSE; + $stored = apc_fetch($id, $success); + + if ($success === FALSE OR count($stored) !== 3) + { + return FALSE; + } + + list($data, $time, $ttl) = $stored; + + return array( + 'expire' => $time + $ttl, + 'mtime' => $time, + 'data' => unserialize($data) + ); + } + + // ------------------------------------------------------------------------ + + /** + * is_supported() + * + * Check to see if APC is available on this system, bail if it isn't. + * + * @return bool + */ + public function is_supported() + { + return (extension_loaded('apc') && ini_get('apc.enabled')); + } +} \ No newline at end of file -- cgit v1.2.3-24-g4f1b From f5e1e6dac46e11b6eca3f1708e15c662400eef30 Mon Sep 17 00:00:00 2001 From: katsew Date: Mon, 20 Feb 2017 14:15:41 +0900 Subject: Correct method and docs Signed-off-by: katsew --- system/libraries/Cache/drivers/Cache_apcu.php | 32 +++++++++++++-------------- 1 file changed, 16 insertions(+), 16 deletions(-) (limited to 'system/libraries') diff --git a/system/libraries/Cache/drivers/Cache_apcu.php b/system/libraries/Cache/drivers/Cache_apcu.php index 066fe428f..7fa0a0812 100644 --- a/system/libraries/Cache/drivers/Cache_apcu.php +++ b/system/libraries/Cache/drivers/Cache_apcu.php @@ -38,7 +38,7 @@ defined('BASEPATH') OR exit('No direct script access allowed'); /** - * CodeIgniter APC Caching Class + * CodeIgniter APCu Caching Class * * @package CodeIgniter * @subpackage Libraries @@ -46,13 +46,13 @@ defined('BASEPATH') OR exit('No direct script access allowed'); * @author EllisLab Dev Team * @link */ -class CI_Cache_apc extends CI_Driver { +class CI_Cache_apcu extends CI_Driver { /** * Class constructor * * Only present so that an error message is logged - * if APC is not available. + * if APCu is not available. * * @return void */ @@ -60,7 +60,7 @@ class CI_Cache_apc extends CI_Driver { { if ( ! $this->is_supported()) { - log_message('error', 'Cache: Failed to initialize APC; extension not loaded/enabled?'); + log_message('error', 'Cache: Failed to initialize APCu; extension not loaded/enabled?'); } } @@ -78,7 +78,7 @@ class CI_Cache_apc extends CI_Driver { public function get($id) { $success = FALSE; - $data = apc_fetch($id, $success); + $data = apcu_fetch($id, $success); if ($success === TRUE) { @@ -105,7 +105,7 @@ class CI_Cache_apc extends CI_Driver { { $ttl = (int) $ttl; - return apc_store( + return apcu_store( $id, ($raw === TRUE ? $data : array(serialize($data), time(), $ttl)), $ttl @@ -122,7 +122,7 @@ class CI_Cache_apc extends CI_Driver { */ public function delete($id) { - return apc_delete($id); + return apcu_delete($id); } // ------------------------------------------------------------------------ @@ -136,7 +136,7 @@ class CI_Cache_apc extends CI_Driver { */ public function increment($id, $offset = 1) { - return apc_inc($id, $offset); + return apcu_inc($id, $offset); } // ------------------------------------------------------------------------ @@ -150,7 +150,7 @@ class CI_Cache_apc extends CI_Driver { */ public function decrement($id, $offset = 1) { - return apc_dec($id, $offset); + return apcu_dec($id, $offset); } // ------------------------------------------------------------------------ @@ -162,7 +162,7 @@ class CI_Cache_apc extends CI_Driver { */ public function clean() { - return apc_clear_cache('user'); + return apcu_clear_cache(); } // ------------------------------------------------------------------------ @@ -170,12 +170,12 @@ class CI_Cache_apc extends CI_Driver { /** * Cache Info * - * @param string user/filehits + * @param bool Whether to exclude the individual list of cache entries * @return mixed array on success, false on failure */ - public function cache_info($type = NULL) + public function cache_info($limited = FALSE) { - return apc_cache_info($type); + return apcu_cache_info($limited); } // ------------------------------------------------------------------------ @@ -189,7 +189,7 @@ class CI_Cache_apc extends CI_Driver { public function get_metadata($id) { $success = FALSE; - $stored = apc_fetch($id, $success); + $stored = apcu_fetch($id, $success); if ($success === FALSE OR count($stored) !== 3) { @@ -210,12 +210,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. + * Check to see if APCu is available on this system, bail if it isn't. * * @return bool */ public function is_supported() { - return (extension_loaded('apc') && ini_get('apc.enabled')); + return (extension_loaded('apcu') && ini_get('apc.enabled')); } } \ No newline at end of file -- cgit v1.2.3-24-g4f1b From 7e19f24dc10a011dee210930d20be2dd6fecf629 Mon Sep 17 00:00:00 2001 From: katsew Date: Mon, 20 Feb 2017 14:16:04 +0900 Subject: Add apcu driver into valid driver list Signed-off-by: katsew --- system/libraries/Cache/Cache.php | 1 + 1 file changed, 1 insertion(+) (limited to 'system/libraries') diff --git a/system/libraries/Cache/Cache.php b/system/libraries/Cache/Cache.php index 267dffb09..b56f33e74 100644 --- a/system/libraries/Cache/Cache.php +++ b/system/libraries/Cache/Cache.php @@ -55,6 +55,7 @@ class CI_Cache extends CI_Driver_Library { */ protected $valid_drivers = array( 'apc', + 'apcu', 'dummy', 'file', 'memcached', -- cgit v1.2.3-24-g4f1b From 954a34bf3cd00e0ff3e4875beb32a660c72200f7 Mon Sep 17 00:00:00 2001 From: katsew Date: Mon, 20 Feb 2017 20:11:47 +0900 Subject: Change version comment Signed-off-by: katsew --- system/libraries/Cache/drivers/Cache_apcu.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'system/libraries') diff --git a/system/libraries/Cache/drivers/Cache_apcu.php b/system/libraries/Cache/drivers/Cache_apcu.php index 7fa0a0812..a60937339 100644 --- a/system/libraries/Cache/drivers/Cache_apcu.php +++ b/system/libraries/Cache/drivers/Cache_apcu.php @@ -32,7 +32,7 @@ * @copyright Copyright (c) 2014 - 2017, British Columbia Institute of Technology (http://bcit.ca/) * @license http://opensource.org/licenses/MIT MIT License * @link https://codeigniter.com - * @since Version 2.0.0 + * @since Version 3.2.0 * @filesource */ defined('BASEPATH') OR exit('No direct script access allowed'); -- cgit v1.2.3-24-g4f1b From eca48e3c0290f84ef210a8a497a29180098ff67b Mon Sep 17 00:00:00 2001 From: katsew Date: Mon, 20 Feb 2017 20:12:30 +0900 Subject: Change author to dev team Signed-off-by: katsew --- system/libraries/Cache/drivers/Cache_apcu.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'system/libraries') diff --git a/system/libraries/Cache/drivers/Cache_apcu.php b/system/libraries/Cache/drivers/Cache_apcu.php index a60937339..955539d8e 100644 --- a/system/libraries/Cache/drivers/Cache_apcu.php +++ b/system/libraries/Cache/drivers/Cache_apcu.php @@ -43,7 +43,7 @@ defined('BASEPATH') OR exit('No direct script access allowed'); * @package CodeIgniter * @subpackage Libraries * @category Core - * @author EllisLab Dev Team + * @author CodeIgniter Dev team * @link */ class CI_Cache_apcu extends CI_Driver { -- cgit v1.2.3-24-g4f1b From 93d755223f76d01113e239e2913f32d978efc577 Mon Sep 17 00:00:00 2001 From: katsew Date: Mon, 20 Feb 2017 20:13:17 +0900 Subject: Remove unused link comment Signed-off-by: katsew --- system/libraries/Cache/drivers/Cache_apcu.php | 1 - 1 file changed, 1 deletion(-) (limited to 'system/libraries') diff --git a/system/libraries/Cache/drivers/Cache_apcu.php b/system/libraries/Cache/drivers/Cache_apcu.php index 955539d8e..d4a90ace2 100644 --- a/system/libraries/Cache/drivers/Cache_apcu.php +++ b/system/libraries/Cache/drivers/Cache_apcu.php @@ -44,7 +44,6 @@ defined('BASEPATH') OR exit('No direct script access allowed'); * @subpackage Libraries * @category Core * @author CodeIgniter Dev team - * @link */ class CI_Cache_apcu extends CI_Driver { -- cgit v1.2.3-24-g4f1b From d790a06ad50803dfd9778e6eeb8caf799b908b93 Mon Sep 17 00:00:00 2001 From: katsew Date: Mon, 20 Feb 2017 20:16:55 +0900 Subject: Align with spaces Signed-off-by: katsew --- system/libraries/Cache/drivers/Cache_apcu.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'system/libraries') diff --git a/system/libraries/Cache/drivers/Cache_apcu.php b/system/libraries/Cache/drivers/Cache_apcu.php index d4a90ace2..584162d32 100644 --- a/system/libraries/Cache/drivers/Cache_apcu.php +++ b/system/libraries/Cache/drivers/Cache_apcu.php @@ -198,9 +198,9 @@ class CI_Cache_apcu extends CI_Driver { list($data, $time, $ttl) = $stored; return array( - 'expire' => $time + $ttl, - 'mtime' => $time, - 'data' => unserialize($data) + 'expire' => $time + $ttl, + 'mtime' => $time, + 'data' => unserialize($data) ); } -- cgit v1.2.3-24-g4f1b From a729f757bf2c5ef45ae45f9101879f5fdf5a2c0e Mon Sep 17 00:00:00 2001 From: katsew Date: Mon, 20 Feb 2017 20:26:46 +0900 Subject: Remove specific argument from abstraction Signed-off-by: katsew --- system/libraries/Cache/drivers/Cache_apcu.php | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) (limited to 'system/libraries') diff --git a/system/libraries/Cache/drivers/Cache_apcu.php b/system/libraries/Cache/drivers/Cache_apcu.php index 584162d32..56e553395 100644 --- a/system/libraries/Cache/drivers/Cache_apcu.php +++ b/system/libraries/Cache/drivers/Cache_apcu.php @@ -169,12 +169,11 @@ class CI_Cache_apcu extends CI_Driver { /** * Cache Info * - * @param bool Whether to exclude the individual list of cache entries * @return mixed array on success, false on failure */ - public function cache_info($limited = FALSE) + public function cache_info() { - return apcu_cache_info($limited); + return apcu_cache_info(); } // ------------------------------------------------------------------------ -- cgit v1.2.3-24-g4f1b From 1a66dd27a332797a5b11c0b8e90a579338d64268 Mon Sep 17 00:00:00 2001 From: katsew Date: Mon, 20 Feb 2017 21:15:08 +0900 Subject: Remove serialization/deserialization array Signed-off-by: katsew --- system/libraries/Cache/drivers/Cache_apcu.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'system/libraries') diff --git a/system/libraries/Cache/drivers/Cache_apcu.php b/system/libraries/Cache/drivers/Cache_apcu.php index 56e553395..9b7fe877c 100644 --- a/system/libraries/Cache/drivers/Cache_apcu.php +++ b/system/libraries/Cache/drivers/Cache_apcu.php @@ -82,7 +82,7 @@ class CI_Cache_apcu extends CI_Driver { if ($success === TRUE) { return is_array($data) - ? unserialize($data[0]) + ? $data[0] : $data; } @@ -106,7 +106,7 @@ class CI_Cache_apcu extends CI_Driver { return apcu_store( $id, - ($raw === TRUE ? $data : array(serialize($data), time(), $ttl)), + ($raw === TRUE ? $data : array($data, time(), $ttl)), $ttl ); } @@ -199,7 +199,7 @@ class CI_Cache_apcu extends CI_Driver { return array( 'expire' => $time + $ttl, 'mtime' => $time, - 'data' => unserialize($data) + 'data' => $data ); } -- cgit v1.2.3-24-g4f1b