Subversion-Projekte lars-tiefland.ci

Revision

Revision 2242 | Revision 2257 | Zur aktuellen Revision | Details | Vergleich mit vorheriger | Letzte Änderung | Log anzeigen | RSS feed

Revision Autor Zeilennr. Zeile
68 lars 1
<?php
2
/**
3
 * CodeIgniter
4
 *
5
 * An open source application development framework for PHP
6
 *
7
 * This content is released under the MIT License (MIT)
8
 *
2254 lars 9
 * Copyright (c) 2014 - 2017, British Columbia Institute of Technology
68 lars 10
 *
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:
17
 *
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
31
 * @copyright	Copyright (c) 2008 - 2014, EllisLab, Inc. (https://ellislab.com/)
2254 lars 32
 * @copyright	Copyright (c) 2014 - 2017, British Columbia Institute of Technology (http://bcit.ca/)
68 lars 33
 * @license	http://opensource.org/licenses/MIT	MIT License
34
 * @link	https://codeigniter.com
35
 * @since	Version 3.0.0
36
 * @filesource
37
 */
38
defined('BASEPATH') OR exit('No direct script access allowed');
39
 
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
50
 * @link
51
 */
52
class CI_Cache_wincache extends CI_Driver {
53
 
54
	/**
55
	 * Class constructor
56
	 *
57
	 * Only present so that an error message is logged
58
	 * if APC is not available.
59
	 *
60
	 * @return	void
61
	 */
62
	public function __construct()
63
	{
64
		if ( ! $this->is_supported())
65
		{
66
			log_message('error', 'Cache: Failed to initialize Wincache; extension not loaded/enabled?');
67
		}
68
	}
69
 
70
	// ------------------------------------------------------------------------
71
 
72
	/**
73
	 * Get
74
	 *
75
	 * Look for a value in the cache. If it exists, return the data,
76
	 * if not, return FALSE
77
	 *
78
	 * @param	string	$id	Cache Ide
79
	 * @return	mixed	Value that is stored/FALSE on failure
80
	 */
81
	public function get($id)
82
	{
83
		$success = FALSE;
84
		$data = wincache_ucache_get($id, $success);
85
 
86
		// Success returned by reference from wincache_ucache_get()
87
		return ($success) ? $data : FALSE;
88
	}
89
 
90
	// ------------------------------------------------------------------------
91
 
92
	/**
93
	 * Cache Save
94
	 *
95
	 * @param	string	$id	Cache ID
96
	 * @param	mixed	$data	Data to store
97
	 * @param	int	$ttl	Time to live (in seconds)
98
	 * @param	bool	$raw	Whether to store the raw value (unused)
99
	 * @return	bool	true on success/false on failure
100
	 */
101
	public function save($id, $data, $ttl = 60, $raw = FALSE)
102
	{
103
		return wincache_ucache_set($id, $data, $ttl);
104
	}
105
 
106
	// ------------------------------------------------------------------------
107
 
108
	/**
109
	 * Delete from Cache
110
	 *
111
	 * @param	mixed	unique identifier of the item in the cache
112
	 * @return	bool	true on success/false on failure
113
	 */
114
	public function delete($id)
115
	{
116
		return wincache_ucache_delete($id);
117
	}
118
 
119
	// ------------------------------------------------------------------------
120
 
121
	/**
122
	 * Increment a raw value
123
	 *
124
	 * @param	string	$id	Cache ID
125
	 * @param	int	$offset	Step/value to add
126
	 * @return	mixed	New value on success or FALSE on failure
127
	 */
128
	public function increment($id, $offset = 1)
129
	{
130
		$success = FALSE;
131
		$value = wincache_ucache_inc($id, $offset, $success);
132
 
133
		return ($success === TRUE) ? $value : FALSE;
134
	}
135
 
136
	// ------------------------------------------------------------------------
137
 
138
	/**
139
	 * Decrement a raw value
140
	 *
141
	 * @param	string	$id	Cache ID
142
	 * @param	int	$offset	Step/value to reduce by
143
	 * @return	mixed	New value on success or FALSE on failure
144
	 */
145
	public function decrement($id, $offset = 1)
146
	{
147
		$success = FALSE;
148
		$value = wincache_ucache_dec($id, $offset, $success);
149
 
150
		return ($success === TRUE) ? $value : FALSE;
151
	}
152
 
153
	// ------------------------------------------------------------------------
154
 
155
	/**
156
	 * Clean the cache
157
	 *
158
	 * @return	bool	false on failure/true on success
159
	 */
160
	public function clean()
161
	{
162
		return wincache_ucache_clear();
163
	}
164
 
165
	// ------------------------------------------------------------------------
166
 
167
	/**
168
	 * Cache Info
169
	 *
170
	 * @return	mixed	array on success, false on failure
171
	 */
172
	 public function cache_info()
173
	 {
174
		 return wincache_ucache_info(TRUE);
175
	 }
176
 
177
	// ------------------------------------------------------------------------
178
 
179
	/**
180
	 * Get Cache Metadata
181
	 *
182
	 * @param	mixed	key to get cache metadata on
183
	 * @return	mixed	array on success/false on failure
184
	 */
185
	public function get_metadata($id)
186
	{
187
		if ($stored = wincache_ucache_info(FALSE, $id))
188
		{
189
			$age = $stored['ucache_entries'][1]['age_seconds'];
190
			$ttl = $stored['ucache_entries'][1]['ttl_seconds'];
191
			$hitcount = $stored['ucache_entries'][1]['hitcount'];
192
 
193
			return array(
194
				'expire'	=> $ttl - $age,
195
				'hitcount'	=> $hitcount,
196
				'age'		=> $age,
197
				'ttl'		=> $ttl
198
			);
199
		}
200
 
201
		return FALSE;
202
	}
203
 
204
	// ------------------------------------------------------------------------
205
 
206
	/**
207
	 * is_supported()
208
	 *
209
	 * Check to see if WinCache is available on this system, bail if it isn't.
210
	 *
211
	 * @return	bool
212
	 */
213
	public function is_supported()
214
	{
215
		return (extension_loaded('wincache') && ini_get('wincache.ucenabled'));
216
	}
217
}