Mike Davies | 03a5765 | 2012-02-29 17:52:36 -0500 | [diff] [blame] | 1 | <?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 Davies | 100934c | 2012-03-02 19:18:22 -0500 | [diff] [blame] | 7 | * 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 Davies | 03a5765 | 2012-02-29 17:52:36 -0500 | [diff] [blame] | 19 | * @package CodeIgniter |
Mike Davies | 100934c | 2012-03-02 19:18:22 -0500 | [diff] [blame] | 20 | * @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 Davies | 03a5765 | 2012-02-29 17:52:36 -0500 | [diff] [blame] | 23 | * @link http://codeigniter.com |
Andrey Andreev | 6b535f5 | 2012-03-12 22:19:13 +0200 | [diff] [blame^] | 24 | * @since Version 3.0 |
Mike Davies | 100934c | 2012-03-02 19:18:22 -0500 | [diff] [blame] | 25 | * @filesource |
Mike Davies | 03a5765 | 2012-02-29 17:52:36 -0500 | [diff] [blame] | 26 | */ |
| 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 Andreev | 6b535f5 | 2012-03-12 22:19:13 +0200 | [diff] [blame^] | 40 | * @link |
Mike Davies | 03a5765 | 2012-02-29 17:52:36 -0500 | [diff] [blame] | 41 | */ |
| 42 | |
| 43 | class CI_Cache_wincache extends CI_Driver { |
| 44 | |
| 45 | /** |
Andrey Andreev | 6b535f5 | 2012-03-12 22:19:13 +0200 | [diff] [blame^] | 46 | * Get |
Mike Davies | 03a5765 | 2012-02-29 17:52:36 -0500 | [diff] [blame] | 47 | * |
Andrey Andreev | 6b535f5 | 2012-03-12 22:19:13 +0200 | [diff] [blame^] | 48 | * Look for a value in the cache. If it exists, return the data, |
Mike Davies | 03a5765 | 2012-02-29 17:52:36 -0500 | [diff] [blame] | 49 | * if not, return FALSE |
| 50 | * |
Andrey Andreev | 6b535f5 | 2012-03-12 22:19:13 +0200 | [diff] [blame^] | 51 | * @param string |
| 52 | * @return mixed value that is stored/FALSE on failure |
Mike Davies | 03a5765 | 2012-02-29 17:52:36 -0500 | [diff] [blame] | 53 | */ |
| 54 | public function get($id) |
| 55 | { |
Mike Davies | 100934c | 2012-03-02 19:18:22 -0500 | [diff] [blame] | 56 | $success = FALSE; |
| 57 | $data = wincache_ucache_get($id, $success); |
Andrey Andreev | 6b535f5 | 2012-03-12 22:19:13 +0200 | [diff] [blame^] | 58 | |
| 59 | // Success returned by reference from wincache_ucache_get() |
Mike Davies | 100934c | 2012-03-02 19:18:22 -0500 | [diff] [blame] | 60 | return ($success) ? $data : FALSE; |
Mike Davies | 03a5765 | 2012-02-29 17:52:36 -0500 | [diff] [blame] | 61 | } |
| 62 | |
Andrey Andreev | 6b535f5 | 2012-03-12 22:19:13 +0200 | [diff] [blame^] | 63 | // ------------------------------------------------------------------------ |
| 64 | |
Mike Davies | 03a5765 | 2012-02-29 17:52:36 -0500 | [diff] [blame] | 65 | /** |
| 66 | * Cache Save |
| 67 | * |
Andrey Andreev | 6b535f5 | 2012-03-12 22:19:13 +0200 | [diff] [blame^] | 68 | * @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 Davies | 03a5765 | 2012-02-29 17:52:36 -0500 | [diff] [blame] | 72 | */ |
| 73 | public function save($id, $data, $ttl = 60) |
| 74 | { |
| 75 | return wincache_ucache_set($id, $data, $ttl); |
| 76 | } |
Andrey Andreev | 6b535f5 | 2012-03-12 22:19:13 +0200 | [diff] [blame^] | 77 | |
Mike Davies | 03a5765 | 2012-02-29 17:52:36 -0500 | [diff] [blame] | 78 | // ------------------------------------------------------------------------ |
| 79 | |
| 80 | /** |
| 81 | * Delete from Cache |
| 82 | * |
Andrey Andreev | 6b535f5 | 2012-03-12 22:19:13 +0200 | [diff] [blame^] | 83 | * @param mixed unique identifier of the item in the cache |
| 84 | * @param bool true on success/false on failure |
Mike Davies | 03a5765 | 2012-02-29 17:52:36 -0500 | [diff] [blame] | 85 | */ |
| 86 | public function delete($id) |
| 87 | { |
| 88 | return wincache_ucache_delete($id); |
| 89 | } |
| 90 | |
| 91 | // ------------------------------------------------------------------------ |
| 92 | |
| 93 | /** |
| 94 | * Clean the cache |
| 95 | * |
Andrey Andreev | 6b535f5 | 2012-03-12 22:19:13 +0200 | [diff] [blame^] | 96 | * @return bool false on failure/true on success |
Mike Davies | 03a5765 | 2012-02-29 17:52:36 -0500 | [diff] [blame] | 97 | */ |
| 98 | public function clean() |
| 99 | { |
| 100 | return wincache_ucache_clear(); |
| 101 | } |
| 102 | |
| 103 | // ------------------------------------------------------------------------ |
| 104 | |
| 105 | /** |
| 106 | * Cache Info |
| 107 | * |
Andrey Andreev | 6b535f5 | 2012-03-12 22:19:13 +0200 | [diff] [blame^] | 108 | * @return mixed array on success, false on failure |
Mike Davies | 03a5765 | 2012-02-29 17:52:36 -0500 | [diff] [blame] | 109 | */ |
| 110 | public function cache_info() |
| 111 | { |
Andrey Andreev | 6b535f5 | 2012-03-12 22:19:13 +0200 | [diff] [blame^] | 112 | return wincache_ucache_info(TRUE); |
Mike Davies | 03a5765 | 2012-02-29 17:52:36 -0500 | [diff] [blame] | 113 | } |
| 114 | |
| 115 | // ------------------------------------------------------------------------ |
| 116 | |
| 117 | /** |
| 118 | * Get Cache Metadata |
| 119 | * |
Andrey Andreev | 6b535f5 | 2012-03-12 22:19:13 +0200 | [diff] [blame^] | 120 | * @param mixed key to get cache metadata on |
| 121 | * @return mixed array on success/false on failure |
Mike Davies | 03a5765 | 2012-02-29 17:52:36 -0500 | [diff] [blame] | 122 | */ |
| 123 | public function get_metadata($id) |
| 124 | { |
Andrey Andreev | 6b535f5 | 2012-03-12 22:19:13 +0200 | [diff] [blame^] | 125 | if ($stored = wincache_ucache_info(FALSE, $id)) |
Mike Davies | 100934c | 2012-03-02 19:18:22 -0500 | [diff] [blame] | 126 | { |
| 127 | $age = $stored['ucache_entries'][1]['age_seconds']; |
| 128 | $ttl = $stored['ucache_entries'][1]['ttl_seconds']; |
| 129 | $hitcount = $stored['ucache_entries'][1]['hitcount']; |
Mike Davies | 03a5765 | 2012-02-29 17:52:36 -0500 | [diff] [blame] | 130 | |
Mike Davies | 100934c | 2012-03-02 19:18:22 -0500 | [diff] [blame] | 131 | return array( |
| 132 | 'expire' => $ttl - $age, |
| 133 | 'hitcount' => $hitcount, |
| 134 | 'age' => $age, |
| 135 | 'ttl' => $ttl |
| 136 | ); |
| 137 | } |
Andrey Andreev | 6b535f5 | 2012-03-12 22:19:13 +0200 | [diff] [blame^] | 138 | |
| 139 | return FALSE; |
Mike Davies | 03a5765 | 2012-02-29 17:52:36 -0500 | [diff] [blame] | 140 | } |
| 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 Andreev | 6b535f5 | 2012-03-12 22:19:13 +0200 | [diff] [blame^] | 148 | * |
| 149 | * @return bool |
Mike Davies | 03a5765 | 2012-02-29 17:52:36 -0500 | [diff] [blame] | 150 | */ |
| 151 | public function is_supported() |
| 152 | { |
Andrey Andreev | 6b535f5 | 2012-03-12 22:19:13 +0200 | [diff] [blame^] | 153 | if ( ! extension_loaded('wincache')) |
Mike Davies | 03a5765 | 2012-02-29 17:52:36 -0500 | [diff] [blame] | 154 | { |
Mike Davies | 100934c | 2012-03-02 19:18:22 -0500 | [diff] [blame] | 155 | log_message('error', 'The Wincache PHP extension must be loaded to use Wincache Cache.'); |
| 156 | return FALSE; |
Mike Davies | 03a5765 | 2012-02-29 17:52:36 -0500 | [diff] [blame] | 157 | } |
Andrey Andreev | 6b535f5 | 2012-03-12 22:19:13 +0200 | [diff] [blame^] | 158 | |
Mike Davies | 03a5765 | 2012-02-29 17:52:36 -0500 | [diff] [blame] | 159 | return TRUE; |
| 160 | } |
| 161 | |
Mike Davies | 03a5765 | 2012-02-29 17:52:36 -0500 | [diff] [blame] | 162 | } |
Mike Davies | 03a5765 | 2012-02-29 17:52:36 -0500 | [diff] [blame] | 163 | |
| 164 | /* End of file Cache_wincache.php */ |
| 165 | /* Location: ./system/libraries/Cache/drivers/Cache_wincache.php */ |