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 | * |
| 7 | * @package CodeIgniter |
| 8 | * @author Mike Murkovic |
| 9 | * @copyright |
| 10 | * @license http://codeigniter.com/user_guide/license.html |
| 11 | * @link http://codeigniter.com |
| 12 | * @since Version 2.0 |
| 13 | * @filesource |
| 14 | */ |
| 15 | |
| 16 | // ------------------------------------------------------------------------ |
| 17 | |
| 18 | /** |
| 19 | * CodeIgniter Wincache Caching Class |
| 20 | * |
| 21 | * Read more about Wincache functions here: |
| 22 | * http://www.php.net/manual/en/ref.wincache.php |
| 23 | * |
| 24 | * @package CodeIgniter |
| 25 | * @subpackage Libraries |
| 26 | * @category Core |
| 27 | * @author Mike Murkovic |
| 28 | * @link |
| 29 | */ |
| 30 | |
| 31 | class CI_Cache_wincache extends CI_Driver { |
| 32 | |
| 33 | /** |
| 34 | * Get |
| 35 | * |
| 36 | * Look for a value in the cache. If it exists, return the data |
| 37 | * if not, return FALSE |
| 38 | * |
| 39 | * @param string |
| 40 | * @return mixed value that is stored/FALSE on failure |
| 41 | */ |
| 42 | public function get($id) |
| 43 | { |
| 44 | if ($data = wincache_ucache_get($id)) |
| 45 | { |
| 46 | return $data; |
| 47 | } |
| 48 | return FALSE; |
| 49 | } |
| 50 | |
| 51 | // ------------------------------------------------------------------------ |
| 52 | |
| 53 | /** |
| 54 | * Cache Save |
| 55 | * |
| 56 | * @param string Unique Key |
| 57 | * @param mixed Data to store |
| 58 | * @param int Length of time (in seconds) to cache the data |
| 59 | * |
| 60 | * @return boolean true on success/false on failure |
| 61 | */ |
| 62 | public function save($id, $data, $ttl = 60) |
| 63 | { |
| 64 | return wincache_ucache_set($id, $data, $ttl); |
| 65 | } |
| 66 | |
| 67 | // ------------------------------------------------------------------------ |
| 68 | |
| 69 | /** |
| 70 | * Delete from Cache |
| 71 | * |
| 72 | * @param mixed unique identifier of the item in the cache |
| 73 | * @param boolean true on success/false on failure |
| 74 | */ |
| 75 | public function delete($id) |
| 76 | { |
| 77 | return wincache_ucache_delete($id); |
| 78 | } |
| 79 | |
| 80 | // ------------------------------------------------------------------------ |
| 81 | |
| 82 | /** |
| 83 | * Clean the cache |
| 84 | * |
| 85 | * @return boolean false on failure/true on success |
| 86 | */ |
| 87 | public function clean() |
| 88 | { |
| 89 | return wincache_ucache_clear(); |
| 90 | } |
| 91 | |
| 92 | // ------------------------------------------------------------------------ |
| 93 | |
| 94 | /** |
| 95 | * Cache Info |
| 96 | * |
| 97 | * @return mixed array on success, false on failure |
| 98 | */ |
| 99 | public function cache_info() |
| 100 | { |
| 101 | return wincache_ucache_info(true); |
| 102 | } |
| 103 | |
| 104 | // ------------------------------------------------------------------------ |
| 105 | |
| 106 | /** |
| 107 | * Get Cache Metadata |
| 108 | * |
| 109 | * @param mixed key to get cache metadata on |
| 110 | * @return mixed array on success/false on failure |
| 111 | */ |
| 112 | public function get_metadata($id) |
| 113 | { |
| 114 | if ($stored = wincache_ucache_info(false, $id)) |
| 115 | { |
| 116 | $age = $stored['ucache_entries'][1]['age_seconds']; |
| 117 | $ttl = $stored['ucache_entries'][1]['ttl_seconds']; |
| 118 | $hitcount = $stored['ucache_entries'][1]['hitcount']; |
| 119 | |
| 120 | return array( |
| 121 | 'expire' => $ttl - $age, |
| 122 | 'hitcount' => $hitcount, |
| 123 | 'age' => $age, |
| 124 | 'ttl' => $ttl |
| 125 | ); |
| 126 | } |
| 127 | return false; |
| 128 | } |
| 129 | |
| 130 | // ------------------------------------------------------------------------ |
| 131 | |
| 132 | /** |
| 133 | * is_supported() |
| 134 | * |
| 135 | * Check to see if WinCache is available on this system, bail if it isn't. |
| 136 | */ |
| 137 | public function is_supported() |
| 138 | { |
| 139 | if ( ! extension_loaded('wincache') ) |
| 140 | { |
| 141 | log_message('error', 'The Wincache PHP extension must be loaded to use Wincache Cache.'); |
| 142 | return FALSE; |
| 143 | } |
| 144 | |
| 145 | return TRUE; |
| 146 | } |
| 147 | |
| 148 | // ------------------------------------------------------------------------ |
| 149 | |
| 150 | |
| 151 | } |
| 152 | // End Class |
| 153 | |
| 154 | /* End of file Cache_wincache.php */ |
| 155 | /* Location: ./system/libraries/Cache/drivers/Cache_wincache.php */ |