blob: 4592d1dd8312b523586c4bc8947c04c6073bade4 [file] [log] [blame]
Andrey Andreevc5536aa2012-11-01 17:33:58 +02001<?php
Mike Davies03a57652012-02-29 17:52:36 -05002/**
3 * CodeIgniter
4 *
Andrey Andreevfe9309d2015-01-09 17:48:58 +02005 * An open source application development framework for PHP
Mike Davies03a57652012-02-29 17:52:36 -05006 *
Andrey Andreevbdb96ca2014-10-28 00:13:31 +02007 * This content is released under the MIT License (MIT)
Mike Davies100934c2012-03-02 19:18:22 -05008 *
Andrey Andreevfe9309d2015-01-09 17:48:58 +02009 * Copyright (c) 2014 - 2015, British Columbia Institute of Technology
Mike Davies100934c2012-03-02 19:18:22 -050010 *
Andrey Andreevbdb96ca2014-10-28 00:13:31 +020011 * 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 Davies100934c2012-03-02 19:18:22 -050017 *
Andrey Andreevbdb96ca2014-10-28 00:13:31 +020018 * 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
darwinel871754a2014-02-11 17:34:57 +010031 * @copyright Copyright (c) 2008 - 2014, EllisLab, Inc. (http://ellislab.com/)
Andrey Andreevfe9309d2015-01-09 17:48:58 +020032 * @copyright Copyright (c) 2014 - 2015, British Columbia Institute of Technology (http://bcit.ca/)
Andrey Andreevbdb96ca2014-10-28 00:13:31 +020033 * @license http://opensource.org/licenses/MIT MIT License
34 * @link http://codeigniter.com
35 * @since Version 3.0.0
Mike Davies100934c2012-03-02 19:18:22 -050036 * @filesource
Mike Davies03a57652012-02-29 17:52:36 -050037 */
Andrey Andreevc5536aa2012-11-01 17:33:58 +020038defined('BASEPATH') OR exit('No direct script access allowed');
Mike Davies03a57652012-02-29 17:52:36 -050039
Mike Davies03a57652012-02-29 17:52:36 -050040/**
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 Andreev6b535f52012-03-12 22:19:13 +020050 * @link
Mike Davies03a57652012-02-29 17:52:36 -050051 */
Mike Davies03a57652012-02-29 17:52:36 -050052class CI_Cache_wincache extends CI_Driver {
53
54 /**
Andrey Andreev6b535f52012-03-12 22:19:13 +020055 * Get
Mike Davies03a57652012-02-29 17:52:36 -050056 *
Andrey Andreev6b535f52012-03-12 22:19:13 +020057 * Look for a value in the cache. If it exists, return the data,
Mike Davies03a57652012-02-29 17:52:36 -050058 * if not, return FALSE
59 *
Andrey Andreev43d7fa72014-01-09 17:29:45 +020060 * @param string $id Cache Ide
61 * @return mixed Value that is stored/FALSE on failure
Mike Davies03a57652012-02-29 17:52:36 -050062 */
63 public function get($id)
64 {
Mike Davies100934c2012-03-02 19:18:22 -050065 $success = FALSE;
66 $data = wincache_ucache_get($id, $success);
Andrey Andreev6b535f52012-03-12 22:19:13 +020067
68 // Success returned by reference from wincache_ucache_get()
Mike Davies100934c2012-03-02 19:18:22 -050069 return ($success) ? $data : FALSE;
Mike Davies03a57652012-02-29 17:52:36 -050070 }
71
Andrey Andreev6b535f52012-03-12 22:19:13 +020072 // ------------------------------------------------------------------------
73
Mike Davies03a57652012-02-29 17:52:36 -050074 /**
75 * Cache Save
76 *
Andrey Andreev43d7fa72014-01-09 17:29:45 +020077 * @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 Andreevb24b0332012-03-26 15:34:39 +030081 * @return bool true on success/false on failure
Mike Davies03a57652012-02-29 17:52:36 -050082 */
Andrey Andreev43d7fa72014-01-09 17:29:45 +020083 public function save($id, $data, $ttl = 60, $raw = FALSE)
Mike Davies03a57652012-02-29 17:52:36 -050084 {
85 return wincache_ucache_set($id, $data, $ttl);
86 }
Andrey Andreev6b535f52012-03-12 22:19:13 +020087
Mike Davies03a57652012-02-29 17:52:36 -050088 // ------------------------------------------------------------------------
89
90 /**
91 * Delete from Cache
92 *
Andrey Andreev6b535f52012-03-12 22:19:13 +020093 * @param mixed unique identifier of the item in the cache
Timothy Warren0688ac92012-04-20 10:25:04 -040094 * @return bool true on success/false on failure
Mike Davies03a57652012-02-29 17:52:36 -050095 */
96 public function delete($id)
97 {
98 return wincache_ucache_delete($id);
99 }
100
101 // ------------------------------------------------------------------------
102
103 /**
Andrey Andreev43d7fa72014-01-09 17:29:45 +0200104 * 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 Davies03a57652012-02-29 17:52:36 -0500138 * Clean the cache
139 *
Andrey Andreev6b535f52012-03-12 22:19:13 +0200140 * @return bool false on failure/true on success
Mike Davies03a57652012-02-29 17:52:36 -0500141 */
142 public function clean()
143 {
144 return wincache_ucache_clear();
145 }
146
147 // ------------------------------------------------------------------------
148
149 /**
150 * Cache Info
151 *
Andrey Andreev6b535f52012-03-12 22:19:13 +0200152 * @return mixed array on success, false on failure
Mike Davies03a57652012-02-29 17:52:36 -0500153 */
154 public function cache_info()
155 {
Andrey Andreev6b535f52012-03-12 22:19:13 +0200156 return wincache_ucache_info(TRUE);
Mike Davies03a57652012-02-29 17:52:36 -0500157 }
158
159 // ------------------------------------------------------------------------
160
161 /**
162 * Get Cache Metadata
163 *
Andrey Andreev6b535f52012-03-12 22:19:13 +0200164 * @param mixed key to get cache metadata on
165 * @return mixed array on success/false on failure
Mike Davies03a57652012-02-29 17:52:36 -0500166 */
167 public function get_metadata($id)
168 {
Andrey Andreev6b535f52012-03-12 22:19:13 +0200169 if ($stored = wincache_ucache_info(FALSE, $id))
Mike Davies100934c2012-03-02 19:18:22 -0500170 {
171 $age = $stored['ucache_entries'][1]['age_seconds'];
172 $ttl = $stored['ucache_entries'][1]['ttl_seconds'];
173 $hitcount = $stored['ucache_entries'][1]['hitcount'];
Mike Davies03a57652012-02-29 17:52:36 -0500174
Mike Davies100934c2012-03-02 19:18:22 -0500175 return array(
Andrey Andreev838a9d62012-12-03 14:37:47 +0200176 'expire' => $ttl - $age,
177 'hitcount' => $hitcount,
178 'age' => $age,
179 'ttl' => $ttl
Mike Davies100934c2012-03-02 19:18:22 -0500180 );
181 }
Andrey Andreev6b535f52012-03-12 22:19:13 +0200182
183 return FALSE;
Mike Davies03a57652012-02-29 17:52:36 -0500184 }
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 Andreev6b535f52012-03-12 22:19:13 +0200192 *
193 * @return bool
Mike Davies03a57652012-02-29 17:52:36 -0500194 */
195 public function is_supported()
196 {
Andrey Andreev6b535f52012-03-12 22:19:13 +0200197 if ( ! extension_loaded('wincache'))
Mike Davies03a57652012-02-29 17:52:36 -0500198 {
Tyler Brownelld967f722013-07-29 19:06:52 -0400199 log_message('debug', 'The Wincache PHP extension must be loaded to use Wincache Cache.');
Mike Davies100934c2012-03-02 19:18:22 -0500200 return FALSE;
Mike Davies03a57652012-02-29 17:52:36 -0500201 }
Andrey Andreev6b535f52012-03-12 22:19:13 +0200202
Mike Davies03a57652012-02-29 17:52:36 -0500203 return TRUE;
204 }
205
Mike Davies03a57652012-02-29 17:52:36 -0500206}
Mike Davies03a57652012-02-29 17:52:36 -0500207
208/* End of file Cache_wincache.php */
Andrey Andreevb24b0332012-03-26 15:34:39 +0300209/* Location: ./system/libraries/Cache/drivers/Cache_wincache.php */