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