blob: df619d4e6dd4234cbe88e1211290be225d7d1993 [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
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 */
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
Andrey Andreev6b535f52012-03-12 22:19:13 +020040 * @link
Mike Davies03a57652012-02-29 17:52:36 -050041 */
42
43class CI_Cache_wincache extends CI_Driver {
44
45 /**
Andrey Andreev6b535f52012-03-12 22:19:13 +020046 * Get
Mike Davies03a57652012-02-29 17:52:36 -050047 *
Andrey Andreev6b535f52012-03-12 22:19:13 +020048 * Look for a value in the cache. If it exists, return the data,
Mike Davies03a57652012-02-29 17:52:36 -050049 * if not, return FALSE
50 *
Andrey Andreev6b535f52012-03-12 22:19:13 +020051 * @param string
52 * @return mixed value that is stored/FALSE on failure
Mike Davies03a57652012-02-29 17:52:36 -050053 */
54 public function get($id)
55 {
Mike Davies100934c2012-03-02 19:18:22 -050056 $success = FALSE;
57 $data = wincache_ucache_get($id, $success);
Andrey Andreev6b535f52012-03-12 22:19:13 +020058
59 // Success returned by reference from wincache_ucache_get()
Mike Davies100934c2012-03-02 19:18:22 -050060 return ($success) ? $data : FALSE;
Mike Davies03a57652012-02-29 17:52:36 -050061 }
62
Andrey Andreev6b535f52012-03-12 22:19:13 +020063 // ------------------------------------------------------------------------
64
Mike Davies03a57652012-02-29 17:52:36 -050065 /**
66 * Cache Save
67 *
Andrey Andreev6b535f52012-03-12 22:19:13 +020068 * @param string Unique Key
69 * @param mixed Data to store
70 * @param int Length of time (in seconds) to cache the data
71 * @return bool true on success/false on failure
Mike Davies03a57652012-02-29 17:52:36 -050072 */
73 public function save($id, $data, $ttl = 60)
74 {
75 return wincache_ucache_set($id, $data, $ttl);
76 }
Andrey Andreev6b535f52012-03-12 22:19:13 +020077
Mike Davies03a57652012-02-29 17:52:36 -050078 // ------------------------------------------------------------------------
79
80 /**
81 * Delete from Cache
82 *
Andrey Andreev6b535f52012-03-12 22:19:13 +020083 * @param mixed unique identifier of the item in the cache
84 * @param bool true on success/false on failure
Mike Davies03a57652012-02-29 17:52:36 -050085 */
86 public function delete($id)
87 {
88 return wincache_ucache_delete($id);
89 }
90
91 // ------------------------------------------------------------------------
92
93 /**
94 * Clean the cache
95 *
Andrey Andreev6b535f52012-03-12 22:19:13 +020096 * @return bool false on failure/true on success
Mike Davies03a57652012-02-29 17:52:36 -050097 */
98 public function clean()
99 {
100 return wincache_ucache_clear();
101 }
102
103 // ------------------------------------------------------------------------
104
105 /**
106 * Cache Info
107 *
Andrey Andreev6b535f52012-03-12 22:19:13 +0200108 * @return mixed array on success, false on failure
Mike Davies03a57652012-02-29 17:52:36 -0500109 */
110 public function cache_info()
111 {
Andrey Andreev6b535f52012-03-12 22:19:13 +0200112 return wincache_ucache_info(TRUE);
Mike Davies03a57652012-02-29 17:52:36 -0500113 }
114
115 // ------------------------------------------------------------------------
116
117 /**
118 * Get Cache Metadata
119 *
Andrey Andreev6b535f52012-03-12 22:19:13 +0200120 * @param mixed key to get cache metadata on
121 * @return mixed array on success/false on failure
Mike Davies03a57652012-02-29 17:52:36 -0500122 */
123 public function get_metadata($id)
124 {
Andrey Andreev6b535f52012-03-12 22:19:13 +0200125 if ($stored = wincache_ucache_info(FALSE, $id))
Mike Davies100934c2012-03-02 19:18:22 -0500126 {
127 $age = $stored['ucache_entries'][1]['age_seconds'];
128 $ttl = $stored['ucache_entries'][1]['ttl_seconds'];
129 $hitcount = $stored['ucache_entries'][1]['hitcount'];
Mike Davies03a57652012-02-29 17:52:36 -0500130
Mike Davies100934c2012-03-02 19:18:22 -0500131 return array(
132 'expire' => $ttl - $age,
133 'hitcount' => $hitcount,
134 'age' => $age,
135 'ttl' => $ttl
136 );
137 }
Andrey Andreev6b535f52012-03-12 22:19:13 +0200138
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.
Andrey Andreev6b535f52012-03-12 22:19:13 +0200148 *
149 * @return bool
Mike Davies03a57652012-02-29 17:52:36 -0500150 */
151 public function is_supported()
152 {
Andrey Andreev6b535f52012-03-12 22:19:13 +0200153 if ( ! extension_loaded('wincache'))
Mike Davies03a57652012-02-29 17:52:36 -0500154 {
Mike Davies100934c2012-03-02 19:18:22 -0500155 log_message('error', 'The Wincache PHP extension must be loaded to use Wincache Cache.');
156 return FALSE;
Mike Davies03a57652012-02-29 17:52:36 -0500157 }
Andrey Andreev6b535f52012-03-12 22:19:13 +0200158
Mike Davies03a57652012-02-29 17:52:36 -0500159 return TRUE;
160 }
161
Mike Davies03a57652012-02-29 17:52:36 -0500162}
Mike Davies03a57652012-02-29 17:52:36 -0500163
164/* End of file Cache_wincache.php */
165/* Location: ./system/libraries/Cache/drivers/Cache_wincache.php */