blob: b32e66a465e1cc170ce1fcc52b312b471ce52724 [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
Mike Davies03a57652012-02-29 17:52:36 -050028/**
29 * CodeIgniter Wincache Caching Class
30 *
31 * Read more about Wincache functions here:
32 * http://www.php.net/manual/en/ref.wincache.php
33 *
34 * @package CodeIgniter
35 * @subpackage Libraries
36 * @category Core
37 * @author Mike Murkovic
Andrey Andreev6b535f52012-03-12 22:19:13 +020038 * @link
Mike Davies03a57652012-02-29 17:52:36 -050039 */
Mike Davies03a57652012-02-29 17:52:36 -050040class CI_Cache_wincache extends CI_Driver {
41
42 /**
Andrey Andreev6b535f52012-03-12 22:19:13 +020043 * Get
Mike Davies03a57652012-02-29 17:52:36 -050044 *
Andrey Andreev6b535f52012-03-12 22:19:13 +020045 * Look for a value in the cache. If it exists, return the data,
Mike Davies03a57652012-02-29 17:52:36 -050046 * if not, return FALSE
47 *
Andrey Andreev6b535f52012-03-12 22:19:13 +020048 * @param string
49 * @return mixed value that is stored/FALSE on failure
Mike Davies03a57652012-02-29 17:52:36 -050050 */
51 public function get($id)
52 {
Mike Davies100934c2012-03-02 19:18:22 -050053 $success = FALSE;
54 $data = wincache_ucache_get($id, $success);
Andrey Andreev6b535f52012-03-12 22:19:13 +020055
56 // Success returned by reference from wincache_ucache_get()
Mike Davies100934c2012-03-02 19:18:22 -050057 return ($success) ? $data : FALSE;
Mike Davies03a57652012-02-29 17:52:36 -050058 }
59
Andrey Andreev6b535f52012-03-12 22:19:13 +020060 // ------------------------------------------------------------------------
61
Mike Davies03a57652012-02-29 17:52:36 -050062 /**
63 * Cache Save
64 *
Andrey Andreev6b535f52012-03-12 22:19:13 +020065 * @param string Unique Key
66 * @param mixed Data to store
67 * @param int Length of time (in seconds) to cache the data
Andrey Andreevb24b0332012-03-26 15:34:39 +030068 * @return bool true on success/false on failure
Mike Davies03a57652012-02-29 17:52:36 -050069 */
70 public function save($id, $data, $ttl = 60)
71 {
72 return wincache_ucache_set($id, $data, $ttl);
73 }
Andrey Andreev6b535f52012-03-12 22:19:13 +020074
Mike Davies03a57652012-02-29 17:52:36 -050075 // ------------------------------------------------------------------------
76
77 /**
78 * Delete from Cache
79 *
Andrey Andreev6b535f52012-03-12 22:19:13 +020080 * @param mixed unique identifier of the item in the cache
81 * @param bool true on success/false on failure
Mike Davies03a57652012-02-29 17:52:36 -050082 */
83 public function delete($id)
84 {
85 return wincache_ucache_delete($id);
86 }
87
88 // ------------------------------------------------------------------------
89
90 /**
91 * Clean the cache
92 *
Andrey Andreev6b535f52012-03-12 22:19:13 +020093 * @return bool false on failure/true on success
Mike Davies03a57652012-02-29 17:52:36 -050094 */
95 public function clean()
96 {
97 return wincache_ucache_clear();
98 }
99
100 // ------------------------------------------------------------------------
101
102 /**
103 * Cache Info
104 *
Andrey Andreev6b535f52012-03-12 22:19:13 +0200105 * @return mixed array on success, false on failure
Mike Davies03a57652012-02-29 17:52:36 -0500106 */
107 public function cache_info()
108 {
Andrey Andreev6b535f52012-03-12 22:19:13 +0200109 return wincache_ucache_info(TRUE);
Mike Davies03a57652012-02-29 17:52:36 -0500110 }
111
112 // ------------------------------------------------------------------------
113
114 /**
115 * Get Cache Metadata
116 *
Andrey Andreev6b535f52012-03-12 22:19:13 +0200117 * @param mixed key to get cache metadata on
118 * @return mixed array on success/false on failure
Mike Davies03a57652012-02-29 17:52:36 -0500119 */
120 public function get_metadata($id)
121 {
Andrey Andreev6b535f52012-03-12 22:19:13 +0200122 if ($stored = wincache_ucache_info(FALSE, $id))
Mike Davies100934c2012-03-02 19:18:22 -0500123 {
124 $age = $stored['ucache_entries'][1]['age_seconds'];
125 $ttl = $stored['ucache_entries'][1]['ttl_seconds'];
126 $hitcount = $stored['ucache_entries'][1]['hitcount'];
Mike Davies03a57652012-02-29 17:52:36 -0500127
Mike Davies100934c2012-03-02 19:18:22 -0500128 return array(
129 'expire' => $ttl - $age,
130 'hitcount' => $hitcount,
131 'age' => $age,
132 'ttl' => $ttl
133 );
134 }
Andrey Andreev6b535f52012-03-12 22:19:13 +0200135
136 return FALSE;
Mike Davies03a57652012-02-29 17:52:36 -0500137 }
138
139 // ------------------------------------------------------------------------
140
141 /**
142 * is_supported()
143 *
144 * Check to see if WinCache is available on this system, bail if it isn't.
Andrey Andreev6b535f52012-03-12 22:19:13 +0200145 *
146 * @return bool
Mike Davies03a57652012-02-29 17:52:36 -0500147 */
148 public function is_supported()
149 {
Andrey Andreev6b535f52012-03-12 22:19:13 +0200150 if ( ! extension_loaded('wincache'))
Mike Davies03a57652012-02-29 17:52:36 -0500151 {
Mike Davies100934c2012-03-02 19:18:22 -0500152 log_message('error', 'The Wincache PHP extension must be loaded to use Wincache Cache.');
153 return FALSE;
Mike Davies03a57652012-02-29 17:52:36 -0500154 }
Andrey Andreev6b535f52012-03-12 22:19:13 +0200155
Mike Davies03a57652012-02-29 17:52:36 -0500156 return TRUE;
157 }
158
Mike Davies03a57652012-02-29 17:52:36 -0500159}
Mike Davies03a57652012-02-29 17:52:36 -0500160
161/* End of file Cache_wincache.php */
Andrey Andreevb24b0332012-03-26 15:34:39 +0300162/* Location: ./system/libraries/Cache/drivers/Cache_wincache.php */