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 | * |
Mike Davies | 100934c | 2012-03-02 19:18:22 -0500 | [diff] [blame] | 7 | * NOTICE OF LICENSE |
| 8 | * |
| 9 | * Licensed under the Open Software License version 3.0 |
| 10 | * |
| 11 | * This source file is subject to the Open Software License (OSL 3.0) that is |
| 12 | * bundled with this package in the files license.txt / license.rst. It is |
| 13 | * also available through the world wide web at this URL: |
| 14 | * http://opensource.org/licenses/OSL-3.0 |
| 15 | * If you did not receive a copy of the license and are unable to obtain it |
| 16 | * through the world wide web, please send an email to |
| 17 | * licensing@ellislab.com so we can send you a copy immediately. |
| 18 | * |
Mike Davies | 03a5765 | 2012-02-29 17:52:36 -0500 | [diff] [blame] | 19 | * @package CodeIgniter |
Mike Davies | 100934c | 2012-03-02 19:18:22 -0500 | [diff] [blame] | 20 | * @author EllisLab Dev Team |
Andrey Andreev | 80500af | 2013-01-01 08:16:53 +0200 | [diff] [blame] | 21 | * @copyright Copyright (c) 2008 - 2013, EllisLab, Inc. (http://ellislab.com/) |
Mike Davies | 100934c | 2012-03-02 19:18:22 -0500 | [diff] [blame] | 22 | * @license http://opensource.org/licenses/OSL-3.0 Open Software License (OSL 3.0) |
Mike Davies | 03a5765 | 2012-02-29 17:52:36 -0500 | [diff] [blame] | 23 | * @link http://codeigniter.com |
Andrey Andreev | 6b535f5 | 2012-03-12 22:19:13 +0200 | [diff] [blame] | 24 | * @since Version 3.0 |
Mike Davies | 100934c | 2012-03-02 19:18:22 -0500 | [diff] [blame] | 25 | * @filesource |
Mike Davies | 03a5765 | 2012-02-29 17:52:36 -0500 | [diff] [blame] | 26 | */ |
Andrey Andreev | c5536aa | 2012-11-01 17:33:58 +0200 | [diff] [blame] | 27 | defined('BASEPATH') OR exit('No direct script access allowed'); |
Mike Davies | 03a5765 | 2012-02-29 17:52:36 -0500 | [diff] [blame] | 28 | |
Mike Davies | 03a5765 | 2012-02-29 17:52:36 -0500 | [diff] [blame] | 29 | /** |
| 30 | * CodeIgniter Wincache Caching Class |
| 31 | * |
| 32 | * Read more about Wincache functions here: |
| 33 | * http://www.php.net/manual/en/ref.wincache.php |
| 34 | * |
| 35 | * @package CodeIgniter |
| 36 | * @subpackage Libraries |
| 37 | * @category Core |
| 38 | * @author Mike Murkovic |
Andrey Andreev | 6b535f5 | 2012-03-12 22:19:13 +0200 | [diff] [blame] | 39 | * @link |
Mike Davies | 03a5765 | 2012-02-29 17:52:36 -0500 | [diff] [blame] | 40 | */ |
Mike Davies | 03a5765 | 2012-02-29 17:52:36 -0500 | [diff] [blame] | 41 | class CI_Cache_wincache extends CI_Driver { |
| 42 | |
| 43 | /** |
Andrey Andreev | 6b535f5 | 2012-03-12 22:19:13 +0200 | [diff] [blame] | 44 | * Get |
Mike Davies | 03a5765 | 2012-02-29 17:52:36 -0500 | [diff] [blame] | 45 | * |
Andrey Andreev | 6b535f5 | 2012-03-12 22:19:13 +0200 | [diff] [blame] | 46 | * 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] | 47 | * if not, return FALSE |
| 48 | * |
Andrey Andreev | 43d7fa7 | 2014-01-09 17:29:45 +0200 | [diff] [blame^] | 49 | * @param string $id Cache Ide |
| 50 | * @return mixed Value that is stored/FALSE on failure |
Mike Davies | 03a5765 | 2012-02-29 17:52:36 -0500 | [diff] [blame] | 51 | */ |
| 52 | public function get($id) |
| 53 | { |
Mike Davies | 100934c | 2012-03-02 19:18:22 -0500 | [diff] [blame] | 54 | $success = FALSE; |
| 55 | $data = wincache_ucache_get($id, $success); |
Andrey Andreev | 6b535f5 | 2012-03-12 22:19:13 +0200 | [diff] [blame] | 56 | |
| 57 | // Success returned by reference from wincache_ucache_get() |
Mike Davies | 100934c | 2012-03-02 19:18:22 -0500 | [diff] [blame] | 58 | return ($success) ? $data : FALSE; |
Mike Davies | 03a5765 | 2012-02-29 17:52:36 -0500 | [diff] [blame] | 59 | } |
| 60 | |
Andrey Andreev | 6b535f5 | 2012-03-12 22:19:13 +0200 | [diff] [blame] | 61 | // ------------------------------------------------------------------------ |
| 62 | |
Mike Davies | 03a5765 | 2012-02-29 17:52:36 -0500 | [diff] [blame] | 63 | /** |
| 64 | * Cache Save |
| 65 | * |
Andrey Andreev | 43d7fa7 | 2014-01-09 17:29:45 +0200 | [diff] [blame^] | 66 | * @param string $id Cache ID |
| 67 | * @param mixed $data Data to store |
| 68 | * @param int $ttl Time to live (in seconds) |
| 69 | * @param bool $raw Whether to store the raw value (unused) |
Andrey Andreev | b24b033 | 2012-03-26 15:34:39 +0300 | [diff] [blame] | 70 | * @return bool true on success/false on failure |
Mike Davies | 03a5765 | 2012-02-29 17:52:36 -0500 | [diff] [blame] | 71 | */ |
Andrey Andreev | 43d7fa7 | 2014-01-09 17:29:45 +0200 | [diff] [blame^] | 72 | public function save($id, $data, $ttl = 60, $raw = FALSE) |
Mike Davies | 03a5765 | 2012-02-29 17:52:36 -0500 | [diff] [blame] | 73 | { |
| 74 | return wincache_ucache_set($id, $data, $ttl); |
| 75 | } |
Andrey Andreev | 6b535f5 | 2012-03-12 22:19:13 +0200 | [diff] [blame] | 76 | |
Mike Davies | 03a5765 | 2012-02-29 17:52:36 -0500 | [diff] [blame] | 77 | // ------------------------------------------------------------------------ |
| 78 | |
| 79 | /** |
| 80 | * Delete from Cache |
| 81 | * |
Andrey Andreev | 6b535f5 | 2012-03-12 22:19:13 +0200 | [diff] [blame] | 82 | * @param mixed unique identifier of the item in the cache |
Timothy Warren | 0688ac9 | 2012-04-20 10:25:04 -0400 | [diff] [blame] | 83 | * @return bool true on success/false on failure |
Mike Davies | 03a5765 | 2012-02-29 17:52:36 -0500 | [diff] [blame] | 84 | */ |
| 85 | public function delete($id) |
| 86 | { |
| 87 | return wincache_ucache_delete($id); |
| 88 | } |
| 89 | |
| 90 | // ------------------------------------------------------------------------ |
| 91 | |
| 92 | /** |
Andrey Andreev | 43d7fa7 | 2014-01-09 17:29:45 +0200 | [diff] [blame^] | 93 | * Increment a raw value |
| 94 | * |
| 95 | * @param string $id Cache ID |
| 96 | * @param int $offset Step/value to add |
| 97 | * @return mixed New value on success or FALSE on failure |
| 98 | */ |
| 99 | public function increment($id, $offset = 1) |
| 100 | { |
| 101 | $success = FALSE; |
| 102 | $value = wincache_ucache_inc($id, $offset, $success); |
| 103 | |
| 104 | return ($success === TRUE) ? $value : FALSE; |
| 105 | } |
| 106 | |
| 107 | // ------------------------------------------------------------------------ |
| 108 | |
| 109 | /** |
| 110 | * Decrement a raw value |
| 111 | * |
| 112 | * @param string $id Cache ID |
| 113 | * @param int $offset Step/value to reduce by |
| 114 | * @return mixed New value on success or FALSE on failure |
| 115 | */ |
| 116 | public function decrement($id, $offset = 1) |
| 117 | { |
| 118 | $success = FALSE; |
| 119 | $value = wincache_ucache_dec($id, $offset, $success); |
| 120 | |
| 121 | return ($success === TRUE) ? $value : FALSE; |
| 122 | } |
| 123 | |
| 124 | // ------------------------------------------------------------------------ |
| 125 | |
| 126 | /** |
Mike Davies | 03a5765 | 2012-02-29 17:52:36 -0500 | [diff] [blame] | 127 | * Clean the cache |
| 128 | * |
Andrey Andreev | 6b535f5 | 2012-03-12 22:19:13 +0200 | [diff] [blame] | 129 | * @return bool false on failure/true on success |
Mike Davies | 03a5765 | 2012-02-29 17:52:36 -0500 | [diff] [blame] | 130 | */ |
| 131 | public function clean() |
| 132 | { |
| 133 | return wincache_ucache_clear(); |
| 134 | } |
| 135 | |
| 136 | // ------------------------------------------------------------------------ |
| 137 | |
| 138 | /** |
| 139 | * Cache Info |
| 140 | * |
Andrey Andreev | 6b535f5 | 2012-03-12 22:19:13 +0200 | [diff] [blame] | 141 | * @return mixed array on success, false on failure |
Mike Davies | 03a5765 | 2012-02-29 17:52:36 -0500 | [diff] [blame] | 142 | */ |
| 143 | public function cache_info() |
| 144 | { |
Andrey Andreev | 6b535f5 | 2012-03-12 22:19:13 +0200 | [diff] [blame] | 145 | return wincache_ucache_info(TRUE); |
Mike Davies | 03a5765 | 2012-02-29 17:52:36 -0500 | [diff] [blame] | 146 | } |
| 147 | |
| 148 | // ------------------------------------------------------------------------ |
| 149 | |
| 150 | /** |
| 151 | * Get Cache Metadata |
| 152 | * |
Andrey Andreev | 6b535f5 | 2012-03-12 22:19:13 +0200 | [diff] [blame] | 153 | * @param mixed key to get cache metadata on |
| 154 | * @return mixed array on success/false on failure |
Mike Davies | 03a5765 | 2012-02-29 17:52:36 -0500 | [diff] [blame] | 155 | */ |
| 156 | public function get_metadata($id) |
| 157 | { |
Andrey Andreev | 6b535f5 | 2012-03-12 22:19:13 +0200 | [diff] [blame] | 158 | if ($stored = wincache_ucache_info(FALSE, $id)) |
Mike Davies | 100934c | 2012-03-02 19:18:22 -0500 | [diff] [blame] | 159 | { |
| 160 | $age = $stored['ucache_entries'][1]['age_seconds']; |
| 161 | $ttl = $stored['ucache_entries'][1]['ttl_seconds']; |
| 162 | $hitcount = $stored['ucache_entries'][1]['hitcount']; |
Mike Davies | 03a5765 | 2012-02-29 17:52:36 -0500 | [diff] [blame] | 163 | |
Mike Davies | 100934c | 2012-03-02 19:18:22 -0500 | [diff] [blame] | 164 | return array( |
Andrey Andreev | 838a9d6 | 2012-12-03 14:37:47 +0200 | [diff] [blame] | 165 | 'expire' => $ttl - $age, |
| 166 | 'hitcount' => $hitcount, |
| 167 | 'age' => $age, |
| 168 | 'ttl' => $ttl |
Mike Davies | 100934c | 2012-03-02 19:18:22 -0500 | [diff] [blame] | 169 | ); |
| 170 | } |
Andrey Andreev | 6b535f5 | 2012-03-12 22:19:13 +0200 | [diff] [blame] | 171 | |
| 172 | return FALSE; |
Mike Davies | 03a5765 | 2012-02-29 17:52:36 -0500 | [diff] [blame] | 173 | } |
| 174 | |
| 175 | // ------------------------------------------------------------------------ |
| 176 | |
| 177 | /** |
| 178 | * is_supported() |
| 179 | * |
| 180 | * 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] | 181 | * |
| 182 | * @return bool |
Mike Davies | 03a5765 | 2012-02-29 17:52:36 -0500 | [diff] [blame] | 183 | */ |
| 184 | public function is_supported() |
| 185 | { |
Andrey Andreev | 6b535f5 | 2012-03-12 22:19:13 +0200 | [diff] [blame] | 186 | if ( ! extension_loaded('wincache')) |
Mike Davies | 03a5765 | 2012-02-29 17:52:36 -0500 | [diff] [blame] | 187 | { |
Tyler Brownell | d967f72 | 2013-07-29 19:06:52 -0400 | [diff] [blame] | 188 | 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] | 189 | return FALSE; |
Mike Davies | 03a5765 | 2012-02-29 17:52:36 -0500 | [diff] [blame] | 190 | } |
Andrey Andreev | 6b535f5 | 2012-03-12 22:19:13 +0200 | [diff] [blame] | 191 | |
Mike Davies | 03a5765 | 2012-02-29 17:52:36 -0500 | [diff] [blame] | 192 | return TRUE; |
| 193 | } |
| 194 | |
Mike Davies | 03a5765 | 2012-02-29 17:52:36 -0500 | [diff] [blame] | 195 | } |
Mike Davies | 03a5765 | 2012-02-29 17:52:36 -0500 | [diff] [blame] | 196 | |
| 197 | /* End of file Cache_wincache.php */ |
Andrey Andreev | b24b033 | 2012-03-26 15:34:39 +0300 | [diff] [blame] | 198 | /* Location: ./system/libraries/Cache/drivers/Cache_wincache.php */ |