blob: 9154f3fceb66272b0c94c320e2a6d2818a5c7a8f [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 Andreevc5536aa2012-11-01 17:33:58 +020021 * @copyright Copyright (c) 2008 - 2012, 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 Andreev6b535f52012-03-12 22:19:13 +020049 * @param string
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 Andreev6b535f52012-03-12 22:19:13 +020066 * @param string Unique Key
67 * @param mixed Data to store
68 * @param int Length of time (in seconds) to cache the data
Andrey Andreevb24b0332012-03-26 15:34:39 +030069 * @return bool true on success/false on failure
Mike Davies03a57652012-02-29 17:52:36 -050070 */
71 public function save($id, $data, $ttl = 60)
72 {
73 return wincache_ucache_set($id, $data, $ttl);
74 }
Andrey Andreev6b535f52012-03-12 22:19:13 +020075
Mike Davies03a57652012-02-29 17:52:36 -050076 // ------------------------------------------------------------------------
77
78 /**
79 * Delete from Cache
80 *
Andrey Andreev6b535f52012-03-12 22:19:13 +020081 * @param mixed unique identifier of the item in the cache
Timothy Warren0688ac92012-04-20 10:25:04 -040082 * @return bool true on success/false on failure
Mike Davies03a57652012-02-29 17:52:36 -050083 */
84 public function delete($id)
85 {
86 return wincache_ucache_delete($id);
87 }
88
89 // ------------------------------------------------------------------------
90
91 /**
92 * Clean the cache
93 *
Andrey Andreev6b535f52012-03-12 22:19:13 +020094 * @return bool false on failure/true on success
Mike Davies03a57652012-02-29 17:52:36 -050095 */
96 public function clean()
97 {
98 return wincache_ucache_clear();
99 }
100
101 // ------------------------------------------------------------------------
102
103 /**
104 * Cache Info
105 *
Andrey Andreev6b535f52012-03-12 22:19:13 +0200106 * @return mixed array on success, false on failure
Mike Davies03a57652012-02-29 17:52:36 -0500107 */
108 public function cache_info()
109 {
Andrey Andreev6b535f52012-03-12 22:19:13 +0200110 return wincache_ucache_info(TRUE);
Mike Davies03a57652012-02-29 17:52:36 -0500111 }
112
113 // ------------------------------------------------------------------------
114
115 /**
116 * Get Cache Metadata
117 *
Andrey Andreev6b535f52012-03-12 22:19:13 +0200118 * @param mixed key to get cache metadata on
119 * @return mixed array on success/false on failure
Mike Davies03a57652012-02-29 17:52:36 -0500120 */
121 public function get_metadata($id)
122 {
Andrey Andreev6b535f52012-03-12 22:19:13 +0200123 if ($stored = wincache_ucache_info(FALSE, $id))
Mike Davies100934c2012-03-02 19:18:22 -0500124 {
125 $age = $stored['ucache_entries'][1]['age_seconds'];
126 $ttl = $stored['ucache_entries'][1]['ttl_seconds'];
127 $hitcount = $stored['ucache_entries'][1]['hitcount'];
Mike Davies03a57652012-02-29 17:52:36 -0500128
Mike Davies100934c2012-03-02 19:18:22 -0500129 return array(
Andrey Andreev838a9d62012-12-03 14:37:47 +0200130 'expire' => $ttl - $age,
131 'hitcount' => $hitcount,
132 'age' => $age,
133 'ttl' => $ttl
Mike Davies100934c2012-03-02 19:18:22 -0500134 );
135 }
Andrey Andreev6b535f52012-03-12 22:19:13 +0200136
137 return FALSE;
Mike Davies03a57652012-02-29 17:52:36 -0500138 }
139
140 // ------------------------------------------------------------------------
141
142 /**
143 * is_supported()
144 *
145 * Check to see if WinCache is available on this system, bail if it isn't.
Andrey Andreev6b535f52012-03-12 22:19:13 +0200146 *
147 * @return bool
Mike Davies03a57652012-02-29 17:52:36 -0500148 */
149 public function is_supported()
150 {
Andrey Andreev6b535f52012-03-12 22:19:13 +0200151 if ( ! extension_loaded('wincache'))
Mike Davies03a57652012-02-29 17:52:36 -0500152 {
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 }
Andrey Andreev6b535f52012-03-12 22:19:13 +0200156
Mike Davies03a57652012-02-29 17:52:36 -0500157 return TRUE;
158 }
159
Mike Davies03a57652012-02-29 17:52:36 -0500160}
Mike Davies03a57652012-02-29 17:52:36 -0500161
162/* End of file Cache_wincache.php */
Andrey Andreevb24b0332012-03-26 15:34:39 +0300163/* Location: ./system/libraries/Cache/drivers/Cache_wincache.php */