blob: 25c18ab58ef2ea823be7b7fc64edf054d562f3a5 [file] [log] [blame]
Andrey Andreevc5536aa2012-11-01 17:33:58 +02001<?php
Mike Davies03a57652012-02-29 17:52:36 -05002/**
3 * CodeIgniter
4 *
vlakofffe832492012-07-13 20:40:06 +02005 * An open source application development framework for PHP 5.2.4 or newer
Mike Davies03a57652012-02-29 17:52:36 -05006 *
Mike Davies100934c2012-03-02 19:18:22 -05007 * 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 Davies03a57652012-02-29 17:52:36 -050019 * @package CodeIgniter
Mike Davies100934c2012-03-02 19:18:22 -050020 * @author EllisLab Dev Team
Andrey Andreev80500af2013-01-01 08:16:53 +020021 * @copyright Copyright (c) 2008 - 2013, EllisLab, Inc. (http://ellislab.com/)
Mike Davies100934c2012-03-02 19:18:22 -050022 * @license http://opensource.org/licenses/OSL-3.0 Open Software License (OSL 3.0)
Mike Davies03a57652012-02-29 17:52:36 -050023 * @link http://codeigniter.com
Andrey Andreev6b535f52012-03-12 22:19:13 +020024 * @since Version 3.0
Mike Davies100934c2012-03-02 19:18:22 -050025 * @filesource
Mike Davies03a57652012-02-29 17:52:36 -050026 */
Andrey Andreevc5536aa2012-11-01 17:33:58 +020027defined('BASEPATH') OR exit('No direct script access allowed');
Mike Davies03a57652012-02-29 17:52:36 -050028
Mike Davies03a57652012-02-29 17:52:36 -050029/**
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 Andreev6b535f52012-03-12 22:19:13 +020039 * @link
Mike Davies03a57652012-02-29 17:52:36 -050040 */
Mike Davies03a57652012-02-29 17:52:36 -050041class CI_Cache_wincache extends CI_Driver {
42
43 /**
Andrey Andreev6b535f52012-03-12 22:19:13 +020044 * Get
Mike Davies03a57652012-02-29 17:52:36 -050045 *
Andrey Andreev6b535f52012-03-12 22:19:13 +020046 * Look for a value in the cache. If it exists, return the data,
Mike Davies03a57652012-02-29 17:52:36 -050047 * if not, return FALSE
48 *
Andrey Andreev43d7fa72014-01-09 17:29:45 +020049 * @param string $id Cache Ide
50 * @return mixed Value that is stored/FALSE on failure
Mike Davies03a57652012-02-29 17:52:36 -050051 */
52 public function get($id)
53 {
Mike Davies100934c2012-03-02 19:18:22 -050054 $success = FALSE;
55 $data = wincache_ucache_get($id, $success);
Andrey Andreev6b535f52012-03-12 22:19:13 +020056
57 // Success returned by reference from wincache_ucache_get()
Mike Davies100934c2012-03-02 19:18:22 -050058 return ($success) ? $data : FALSE;
Mike Davies03a57652012-02-29 17:52:36 -050059 }
60
Andrey Andreev6b535f52012-03-12 22:19:13 +020061 // ------------------------------------------------------------------------
62
Mike Davies03a57652012-02-29 17:52:36 -050063 /**
64 * Cache Save
65 *
Andrey Andreev43d7fa72014-01-09 17:29:45 +020066 * @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 Andreevb24b0332012-03-26 15:34:39 +030070 * @return bool true on success/false on failure
Mike Davies03a57652012-02-29 17:52:36 -050071 */
Andrey Andreev43d7fa72014-01-09 17:29:45 +020072 public function save($id, $data, $ttl = 60, $raw = FALSE)
Mike Davies03a57652012-02-29 17:52:36 -050073 {
74 return wincache_ucache_set($id, $data, $ttl);
75 }
Andrey Andreev6b535f52012-03-12 22:19:13 +020076
Mike Davies03a57652012-02-29 17:52:36 -050077 // ------------------------------------------------------------------------
78
79 /**
80 * Delete from Cache
81 *
Andrey Andreev6b535f52012-03-12 22:19:13 +020082 * @param mixed unique identifier of the item in the cache
Timothy Warren0688ac92012-04-20 10:25:04 -040083 * @return bool true on success/false on failure
Mike Davies03a57652012-02-29 17:52:36 -050084 */
85 public function delete($id)
86 {
87 return wincache_ucache_delete($id);
88 }
89
90 // ------------------------------------------------------------------------
91
92 /**
Andrey Andreev43d7fa72014-01-09 17:29:45 +020093 * 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 Davies03a57652012-02-29 17:52:36 -0500127 * Clean the cache
128 *
Andrey Andreev6b535f52012-03-12 22:19:13 +0200129 * @return bool false on failure/true on success
Mike Davies03a57652012-02-29 17:52:36 -0500130 */
131 public function clean()
132 {
133 return wincache_ucache_clear();
134 }
135
136 // ------------------------------------------------------------------------
137
138 /**
139 * Cache Info
140 *
Andrey Andreev6b535f52012-03-12 22:19:13 +0200141 * @return mixed array on success, false on failure
Mike Davies03a57652012-02-29 17:52:36 -0500142 */
143 public function cache_info()
144 {
Andrey Andreev6b535f52012-03-12 22:19:13 +0200145 return wincache_ucache_info(TRUE);
Mike Davies03a57652012-02-29 17:52:36 -0500146 }
147
148 // ------------------------------------------------------------------------
149
150 /**
151 * Get Cache Metadata
152 *
Andrey Andreev6b535f52012-03-12 22:19:13 +0200153 * @param mixed key to get cache metadata on
154 * @return mixed array on success/false on failure
Mike Davies03a57652012-02-29 17:52:36 -0500155 */
156 public function get_metadata($id)
157 {
Andrey Andreev6b535f52012-03-12 22:19:13 +0200158 if ($stored = wincache_ucache_info(FALSE, $id))
Mike Davies100934c2012-03-02 19:18:22 -0500159 {
160 $age = $stored['ucache_entries'][1]['age_seconds'];
161 $ttl = $stored['ucache_entries'][1]['ttl_seconds'];
162 $hitcount = $stored['ucache_entries'][1]['hitcount'];
Mike Davies03a57652012-02-29 17:52:36 -0500163
Mike Davies100934c2012-03-02 19:18:22 -0500164 return array(
Andrey Andreev838a9d62012-12-03 14:37:47 +0200165 'expire' => $ttl - $age,
166 'hitcount' => $hitcount,
167 'age' => $age,
168 'ttl' => $ttl
Mike Davies100934c2012-03-02 19:18:22 -0500169 );
170 }
Andrey Andreev6b535f52012-03-12 22:19:13 +0200171
172 return FALSE;
Mike Davies03a57652012-02-29 17:52:36 -0500173 }
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 Andreev6b535f52012-03-12 22:19:13 +0200181 *
182 * @return bool
Mike Davies03a57652012-02-29 17:52:36 -0500183 */
184 public function is_supported()
185 {
Andrey Andreev6b535f52012-03-12 22:19:13 +0200186 if ( ! extension_loaded('wincache'))
Mike Davies03a57652012-02-29 17:52:36 -0500187 {
Tyler Brownelld967f722013-07-29 19:06:52 -0400188 log_message('debug', 'The Wincache PHP extension must be loaded to use Wincache Cache.');
Mike Davies100934c2012-03-02 19:18:22 -0500189 return FALSE;
Mike Davies03a57652012-02-29 17:52:36 -0500190 }
Andrey Andreev6b535f52012-03-12 22:19:13 +0200191
Mike Davies03a57652012-02-29 17:52:36 -0500192 return TRUE;
193 }
194
Mike Davies03a57652012-02-29 17:52:36 -0500195}
Mike Davies03a57652012-02-29 17:52:36 -0500196
197/* End of file Cache_wincache.php */
Andrey Andreevb24b0332012-03-26 15:34:39 +0300198/* Location: ./system/libraries/Cache/drivers/Cache_wincache.php */