Andrey Andreev | c5536aa | 2012-11-01 17:33:58 +0200 | [diff] [blame] | 1 | <?php |
Mike Davies | 03a5765 | 2012-02-29 17:52:36 -0500 | [diff] [blame] | 2 | /** |
| 3 | * CodeIgniter |
| 4 | * |
vlakoff | fe83249 | 2012-07-13 20:40:06 +0200 | [diff] [blame] | 5 | * An open source application development framework for PHP 5.2.4 or newer |
Mike Davies | 03a5765 | 2012-02-29 17:52:36 -0500 | [diff] [blame] | 6 | * |
Andrey Andreev | bdb96ca | 2014-10-28 00:13:31 +0200 | [diff] [blame^] | 7 | * This content is released under the MIT License (MIT) |
Mike Davies | 100934c | 2012-03-02 19:18:22 -0500 | [diff] [blame] | 8 | * |
Andrey Andreev | bdb96ca | 2014-10-28 00:13:31 +0200 | [diff] [blame^] | 9 | * Copyright (c) 2014, British Columbia Institute of Technology |
Mike Davies | 100934c | 2012-03-02 19:18:22 -0500 | [diff] [blame] | 10 | * |
Andrey Andreev | bdb96ca | 2014-10-28 00:13:31 +0200 | [diff] [blame^] | 11 | * Permission is hereby granted, free of charge, to any person obtaining a copy |
| 12 | * of this software and associated documentation files (the "Software"), to deal |
| 13 | * in the Software without restriction, including without limitation the rights |
| 14 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
| 15 | * copies of the Software, and to permit persons to whom the Software is |
| 16 | * furnished to do so, subject to the following conditions: |
Mike Davies | 100934c | 2012-03-02 19:18:22 -0500 | [diff] [blame] | 17 | * |
Andrey Andreev | bdb96ca | 2014-10-28 00:13:31 +0200 | [diff] [blame^] | 18 | * The above copyright notice and this permission notice shall be included in |
| 19 | * all copies or substantial portions of the Software. |
| 20 | * |
| 21 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
| 22 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
| 23 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
| 24 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
| 25 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
| 26 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN |
| 27 | * THE SOFTWARE. |
| 28 | * |
| 29 | * @package CodeIgniter |
| 30 | * @author EllisLab Dev Team |
darwinel | 871754a | 2014-02-11 17:34:57 +0100 | [diff] [blame] | 31 | * @copyright Copyright (c) 2008 - 2014, EllisLab, Inc. (http://ellislab.com/) |
Andrey Andreev | bdb96ca | 2014-10-28 00:13:31 +0200 | [diff] [blame^] | 32 | * @copyright Copyright (c) 2014, British Columbia Institute of Technology (http://bcit.ca/) |
| 33 | * @license http://opensource.org/licenses/MIT MIT License |
| 34 | * @link http://codeigniter.com |
| 35 | * @since Version 3.0.0 |
Mike Davies | 100934c | 2012-03-02 19:18:22 -0500 | [diff] [blame] | 36 | * @filesource |
Mike Davies | 03a5765 | 2012-02-29 17:52:36 -0500 | [diff] [blame] | 37 | */ |
Andrey Andreev | c5536aa | 2012-11-01 17:33:58 +0200 | [diff] [blame] | 38 | defined('BASEPATH') OR exit('No direct script access allowed'); |
Mike Davies | 03a5765 | 2012-02-29 17:52:36 -0500 | [diff] [blame] | 39 | |
Mike Davies | 03a5765 | 2012-02-29 17:52:36 -0500 | [diff] [blame] | 40 | /** |
| 41 | * CodeIgniter Wincache Caching Class |
| 42 | * |
| 43 | * Read more about Wincache functions here: |
| 44 | * http://www.php.net/manual/en/ref.wincache.php |
| 45 | * |
| 46 | * @package CodeIgniter |
| 47 | * @subpackage Libraries |
| 48 | * @category Core |
| 49 | * @author Mike Murkovic |
Andrey Andreev | 6b535f5 | 2012-03-12 22:19:13 +0200 | [diff] [blame] | 50 | * @link |
Mike Davies | 03a5765 | 2012-02-29 17:52:36 -0500 | [diff] [blame] | 51 | */ |
Mike Davies | 03a5765 | 2012-02-29 17:52:36 -0500 | [diff] [blame] | 52 | class CI_Cache_wincache extends CI_Driver { |
| 53 | |
| 54 | /** |
Andrey Andreev | 6b535f5 | 2012-03-12 22:19:13 +0200 | [diff] [blame] | 55 | * Get |
Mike Davies | 03a5765 | 2012-02-29 17:52:36 -0500 | [diff] [blame] | 56 | * |
Andrey Andreev | 6b535f5 | 2012-03-12 22:19:13 +0200 | [diff] [blame] | 57 | * Look for a value in the cache. If it exists, return the data, |
Mike Davies | 03a5765 | 2012-02-29 17:52:36 -0500 | [diff] [blame] | 58 | * if not, return FALSE |
| 59 | * |
Andrey Andreev | 43d7fa7 | 2014-01-09 17:29:45 +0200 | [diff] [blame] | 60 | * @param string $id Cache Ide |
| 61 | * @return mixed Value that is stored/FALSE on failure |
Mike Davies | 03a5765 | 2012-02-29 17:52:36 -0500 | [diff] [blame] | 62 | */ |
| 63 | public function get($id) |
| 64 | { |
Mike Davies | 100934c | 2012-03-02 19:18:22 -0500 | [diff] [blame] | 65 | $success = FALSE; |
| 66 | $data = wincache_ucache_get($id, $success); |
Andrey Andreev | 6b535f5 | 2012-03-12 22:19:13 +0200 | [diff] [blame] | 67 | |
| 68 | // Success returned by reference from wincache_ucache_get() |
Mike Davies | 100934c | 2012-03-02 19:18:22 -0500 | [diff] [blame] | 69 | return ($success) ? $data : FALSE; |
Mike Davies | 03a5765 | 2012-02-29 17:52:36 -0500 | [diff] [blame] | 70 | } |
| 71 | |
Andrey Andreev | 6b535f5 | 2012-03-12 22:19:13 +0200 | [diff] [blame] | 72 | // ------------------------------------------------------------------------ |
| 73 | |
Mike Davies | 03a5765 | 2012-02-29 17:52:36 -0500 | [diff] [blame] | 74 | /** |
| 75 | * Cache Save |
| 76 | * |
Andrey Andreev | 43d7fa7 | 2014-01-09 17:29:45 +0200 | [diff] [blame] | 77 | * @param string $id Cache ID |
| 78 | * @param mixed $data Data to store |
| 79 | * @param int $ttl Time to live (in seconds) |
| 80 | * @param bool $raw Whether to store the raw value (unused) |
Andrey Andreev | b24b033 | 2012-03-26 15:34:39 +0300 | [diff] [blame] | 81 | * @return bool true on success/false on failure |
Mike Davies | 03a5765 | 2012-02-29 17:52:36 -0500 | [diff] [blame] | 82 | */ |
Andrey Andreev | 43d7fa7 | 2014-01-09 17:29:45 +0200 | [diff] [blame] | 83 | public function save($id, $data, $ttl = 60, $raw = FALSE) |
Mike Davies | 03a5765 | 2012-02-29 17:52:36 -0500 | [diff] [blame] | 84 | { |
| 85 | return wincache_ucache_set($id, $data, $ttl); |
| 86 | } |
Andrey Andreev | 6b535f5 | 2012-03-12 22:19:13 +0200 | [diff] [blame] | 87 | |
Mike Davies | 03a5765 | 2012-02-29 17:52:36 -0500 | [diff] [blame] | 88 | // ------------------------------------------------------------------------ |
| 89 | |
| 90 | /** |
| 91 | * Delete from Cache |
| 92 | * |
Andrey Andreev | 6b535f5 | 2012-03-12 22:19:13 +0200 | [diff] [blame] | 93 | * @param mixed unique identifier of the item in the cache |
Timothy Warren | 0688ac9 | 2012-04-20 10:25:04 -0400 | [diff] [blame] | 94 | * @return bool true on success/false on failure |
Mike Davies | 03a5765 | 2012-02-29 17:52:36 -0500 | [diff] [blame] | 95 | */ |
| 96 | public function delete($id) |
| 97 | { |
| 98 | return wincache_ucache_delete($id); |
| 99 | } |
| 100 | |
| 101 | // ------------------------------------------------------------------------ |
| 102 | |
| 103 | /** |
Andrey Andreev | 43d7fa7 | 2014-01-09 17:29:45 +0200 | [diff] [blame] | 104 | * Increment a raw value |
| 105 | * |
| 106 | * @param string $id Cache ID |
| 107 | * @param int $offset Step/value to add |
| 108 | * @return mixed New value on success or FALSE on failure |
| 109 | */ |
| 110 | public function increment($id, $offset = 1) |
| 111 | { |
| 112 | $success = FALSE; |
| 113 | $value = wincache_ucache_inc($id, $offset, $success); |
| 114 | |
| 115 | return ($success === TRUE) ? $value : FALSE; |
| 116 | } |
| 117 | |
| 118 | // ------------------------------------------------------------------------ |
| 119 | |
| 120 | /** |
| 121 | * Decrement a raw value |
| 122 | * |
| 123 | * @param string $id Cache ID |
| 124 | * @param int $offset Step/value to reduce by |
| 125 | * @return mixed New value on success or FALSE on failure |
| 126 | */ |
| 127 | public function decrement($id, $offset = 1) |
| 128 | { |
| 129 | $success = FALSE; |
| 130 | $value = wincache_ucache_dec($id, $offset, $success); |
| 131 | |
| 132 | return ($success === TRUE) ? $value : FALSE; |
| 133 | } |
| 134 | |
| 135 | // ------------------------------------------------------------------------ |
| 136 | |
| 137 | /** |
Mike Davies | 03a5765 | 2012-02-29 17:52:36 -0500 | [diff] [blame] | 138 | * Clean the cache |
| 139 | * |
Andrey Andreev | 6b535f5 | 2012-03-12 22:19:13 +0200 | [diff] [blame] | 140 | * @return bool false on failure/true on success |
Mike Davies | 03a5765 | 2012-02-29 17:52:36 -0500 | [diff] [blame] | 141 | */ |
| 142 | public function clean() |
| 143 | { |
| 144 | return wincache_ucache_clear(); |
| 145 | } |
| 146 | |
| 147 | // ------------------------------------------------------------------------ |
| 148 | |
| 149 | /** |
| 150 | * Cache Info |
| 151 | * |
Andrey Andreev | 6b535f5 | 2012-03-12 22:19:13 +0200 | [diff] [blame] | 152 | * @return mixed array on success, false on failure |
Mike Davies | 03a5765 | 2012-02-29 17:52:36 -0500 | [diff] [blame] | 153 | */ |
| 154 | public function cache_info() |
| 155 | { |
Andrey Andreev | 6b535f5 | 2012-03-12 22:19:13 +0200 | [diff] [blame] | 156 | return wincache_ucache_info(TRUE); |
Mike Davies | 03a5765 | 2012-02-29 17:52:36 -0500 | [diff] [blame] | 157 | } |
| 158 | |
| 159 | // ------------------------------------------------------------------------ |
| 160 | |
| 161 | /** |
| 162 | * Get Cache Metadata |
| 163 | * |
Andrey Andreev | 6b535f5 | 2012-03-12 22:19:13 +0200 | [diff] [blame] | 164 | * @param mixed key to get cache metadata on |
| 165 | * @return mixed array on success/false on failure |
Mike Davies | 03a5765 | 2012-02-29 17:52:36 -0500 | [diff] [blame] | 166 | */ |
| 167 | public function get_metadata($id) |
| 168 | { |
Andrey Andreev | 6b535f5 | 2012-03-12 22:19:13 +0200 | [diff] [blame] | 169 | if ($stored = wincache_ucache_info(FALSE, $id)) |
Mike Davies | 100934c | 2012-03-02 19:18:22 -0500 | [diff] [blame] | 170 | { |
| 171 | $age = $stored['ucache_entries'][1]['age_seconds']; |
| 172 | $ttl = $stored['ucache_entries'][1]['ttl_seconds']; |
| 173 | $hitcount = $stored['ucache_entries'][1]['hitcount']; |
Mike Davies | 03a5765 | 2012-02-29 17:52:36 -0500 | [diff] [blame] | 174 | |
Mike Davies | 100934c | 2012-03-02 19:18:22 -0500 | [diff] [blame] | 175 | return array( |
Andrey Andreev | 838a9d6 | 2012-12-03 14:37:47 +0200 | [diff] [blame] | 176 | 'expire' => $ttl - $age, |
| 177 | 'hitcount' => $hitcount, |
| 178 | 'age' => $age, |
| 179 | 'ttl' => $ttl |
Mike Davies | 100934c | 2012-03-02 19:18:22 -0500 | [diff] [blame] | 180 | ); |
| 181 | } |
Andrey Andreev | 6b535f5 | 2012-03-12 22:19:13 +0200 | [diff] [blame] | 182 | |
| 183 | return FALSE; |
Mike Davies | 03a5765 | 2012-02-29 17:52:36 -0500 | [diff] [blame] | 184 | } |
| 185 | |
| 186 | // ------------------------------------------------------------------------ |
| 187 | |
| 188 | /** |
| 189 | * is_supported() |
| 190 | * |
| 191 | * Check to see if WinCache is available on this system, bail if it isn't. |
Andrey Andreev | 6b535f5 | 2012-03-12 22:19:13 +0200 | [diff] [blame] | 192 | * |
| 193 | * @return bool |
Mike Davies | 03a5765 | 2012-02-29 17:52:36 -0500 | [diff] [blame] | 194 | */ |
| 195 | public function is_supported() |
| 196 | { |
Andrey Andreev | 6b535f5 | 2012-03-12 22:19:13 +0200 | [diff] [blame] | 197 | if ( ! extension_loaded('wincache')) |
Mike Davies | 03a5765 | 2012-02-29 17:52:36 -0500 | [diff] [blame] | 198 | { |
Tyler Brownell | d967f72 | 2013-07-29 19:06:52 -0400 | [diff] [blame] | 199 | log_message('debug', 'The Wincache PHP extension must be loaded to use Wincache Cache.'); |
Mike Davies | 100934c | 2012-03-02 19:18:22 -0500 | [diff] [blame] | 200 | return FALSE; |
Mike Davies | 03a5765 | 2012-02-29 17:52:36 -0500 | [diff] [blame] | 201 | } |
Andrey Andreev | 6b535f5 | 2012-03-12 22:19:13 +0200 | [diff] [blame] | 202 | |
Mike Davies | 03a5765 | 2012-02-29 17:52:36 -0500 | [diff] [blame] | 203 | return TRUE; |
| 204 | } |
| 205 | |
Mike Davies | 03a5765 | 2012-02-29 17:52:36 -0500 | [diff] [blame] | 206 | } |
Mike Davies | 03a5765 | 2012-02-29 17:52:36 -0500 | [diff] [blame] | 207 | |
| 208 | /* End of file Cache_wincache.php */ |
Andrey Andreev | b24b033 | 2012-03-26 15:34:39 +0300 | [diff] [blame] | 209 | /* Location: ./system/libraries/Cache/drivers/Cache_wincache.php */ |