blob: 8164b5a7b0475e6dd6e632fc1d53023c9c9b4880 [file] [log] [blame]
Mike Davies03a57652012-02-29 17:52:36 -05001<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
2/**
3 * CodeIgniter
4 *
5 * An open source application development framework for PHP 5.1.6 or newer
6 *
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
21 * @copyright Copyright (c) 2006 - 2012 EllisLab, Inc.
22 * @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
24 * @since Version 2.0
Mike Davies100934c2012-03-02 19:18:22 -050025 * @filesource
Mike Davies03a57652012-02-29 17:52:36 -050026 */
27
28// ------------------------------------------------------------------------
29
30/**
31 * CodeIgniter Wincache Caching Class
32 *
33 * Read more about Wincache functions here:
34 * http://www.php.net/manual/en/ref.wincache.php
35 *
36 * @package CodeIgniter
37 * @subpackage Libraries
38 * @category Core
39 * @author Mike Murkovic
40 * @link
41 */
42
43class CI_Cache_wincache extends CI_Driver {
44
45 /**
46 * Get
47 *
48 * Look for a value in the cache. If it exists, return the data
49 * if not, return FALSE
50 *
51 * @param string
52 * @return mixed value that is stored/FALSE on failure
53 */
54 public function get($id)
55 {
Mike Davies100934c2012-03-02 19:18:22 -050056 $success = FALSE;
57 $data = wincache_ucache_get($id, $success);
58
59 //Success returned by reference from wincache_ucache_get
60 return ($success) ? $data : FALSE;
Mike Davies03a57652012-02-29 17:52:36 -050061 }
62
63 // ------------------------------------------------------------------------
64
65 /**
66 * Cache Save
67 *
68 * @param string Unique Key
69 * @param mixed Data to store
70 * @param int Length of time (in seconds) to cache the data
71 *
72 * @return boolean true on success/false on failure
73 */
74 public function save($id, $data, $ttl = 60)
75 {
76 return wincache_ucache_set($id, $data, $ttl);
77 }
78
79 // ------------------------------------------------------------------------
80
81 /**
82 * Delete from Cache
83 *
84 * @param mixed unique identifier of the item in the cache
85 * @param boolean true on success/false on failure
86 */
87 public function delete($id)
88 {
89 return wincache_ucache_delete($id);
90 }
91
92 // ------------------------------------------------------------------------
93
94 /**
95 * Clean the cache
96 *
97 * @return boolean false on failure/true on success
98 */
99 public function clean()
100 {
101 return wincache_ucache_clear();
102 }
103
104 // ------------------------------------------------------------------------
105
106 /**
107 * Cache Info
108 *
109 * @return mixed array on success, false on failure
110 */
111 public function cache_info()
112 {
113 return wincache_ucache_info(true);
114 }
115
116 // ------------------------------------------------------------------------
117
118 /**
119 * Get Cache Metadata
120 *
121 * @param mixed key to get cache metadata on
122 * @return mixed array on success/false on failure
123 */
124 public function get_metadata($id)
125 {
Mike Davies100934c2012-03-02 19:18:22 -0500126 if ($stored = wincache_ucache_info(false, $id))
127 {
128 $age = $stored['ucache_entries'][1]['age_seconds'];
129 $ttl = $stored['ucache_entries'][1]['ttl_seconds'];
130 $hitcount = $stored['ucache_entries'][1]['hitcount'];
Mike Davies03a57652012-02-29 17:52:36 -0500131
Mike Davies100934c2012-03-02 19:18:22 -0500132 return array(
133 'expire' => $ttl - $age,
134 'hitcount' => $hitcount,
135 'age' => $age,
136 'ttl' => $ttl
137 );
138 }
139 return false;
Mike Davies03a57652012-02-29 17:52:36 -0500140 }
141
142 // ------------------------------------------------------------------------
143
144 /**
145 * is_supported()
146 *
147 * Check to see if WinCache is available on this system, bail if it isn't.
148 */
149 public function is_supported()
150 {
151 if ( ! extension_loaded('wincache') )
152 {
Mike Davies100934c2012-03-02 19:18:22 -0500153 log_message('error', 'The Wincache PHP extension must be loaded to use Wincache Cache.');
154 return FALSE;
Mike Davies03a57652012-02-29 17:52:36 -0500155 }
156
157 return TRUE;
158 }
159
160 // ------------------------------------------------------------------------
161
162
163}
164// End Class
165
166/* End of file Cache_wincache.php */
167/* Location: ./system/libraries/Cache/drivers/Cache_wincache.php */