Andrey Andreev | 7d4ea07 | 2011-12-25 19:23:50 +0200 | [diff] [blame^] | 1 | <?php if ( ! defined('BASEPATH')) exit('No direct script access allowed'); |
Greg Aker | bde25d9 | 2010-12-21 09:31:21 -0600 | [diff] [blame] | 2 | /** |
| 3 | * CodeIgniter |
| 4 | * |
| 5 | * An open source application development framework for PHP 5.1.6 or newer |
| 6 | * |
Derek Jones | f4a4bd8 | 2011-10-20 12:18:42 -0500 | [diff] [blame] | 7 | * NOTICE OF LICENSE |
Andrey Andreev | 7d4ea07 | 2011-12-25 19:23:50 +0200 | [diff] [blame^] | 8 | * |
Derek Jones | f4a4bd8 | 2011-10-20 12:18:42 -0500 | [diff] [blame] | 9 | * Licensed under the Open Software License version 3.0 |
Andrey Andreev | 7d4ea07 | 2011-12-25 19:23:50 +0200 | [diff] [blame^] | 10 | * |
Derek Jones | f4a4bd8 | 2011-10-20 12:18:42 -0500 | [diff] [blame] | 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 | * |
Greg Aker | bde25d9 | 2010-12-21 09:31:21 -0600 | [diff] [blame] | 19 | * @package CodeIgniter |
Derek Jones | f4a4bd8 | 2011-10-20 12:18:42 -0500 | [diff] [blame] | 20 | * @author EllisLab Dev Team |
Derek Jones | 700205a | 2011-01-28 07:44:28 -0600 | [diff] [blame] | 21 | * @copyright Copyright (c) 2006 - 2011 EllisLab, Inc. |
Derek Jones | f4a4bd8 | 2011-10-20 12:18:42 -0500 | [diff] [blame] | 22 | * @license http://opensource.org/licenses/OSL-3.0 Open Software License (OSL 3.0) |
Greg Aker | bde25d9 | 2010-12-21 09:31:21 -0600 | [diff] [blame] | 23 | * @link http://codeigniter.com |
| 24 | * @since Version 2.0 |
Andrey Andreev | 7d4ea07 | 2011-12-25 19:23:50 +0200 | [diff] [blame^] | 25 | * @filesource |
Greg Aker | bde25d9 | 2010-12-21 09:31:21 -0600 | [diff] [blame] | 26 | */ |
| 27 | |
| 28 | // ------------------------------------------------------------------------ |
| 29 | |
| 30 | /** |
Andrey Andreev | 7d4ea07 | 2011-12-25 19:23:50 +0200 | [diff] [blame^] | 31 | * CodeIgniter APC Caching Class |
Greg Aker | bde25d9 | 2010-12-21 09:31:21 -0600 | [diff] [blame] | 32 | * |
| 33 | * @package CodeIgniter |
| 34 | * @subpackage Libraries |
| 35 | * @category Core |
Derek Jones | f4a4bd8 | 2011-10-20 12:18:42 -0500 | [diff] [blame] | 36 | * @author EllisLab Dev Team |
Andrey Andreev | 7d4ea07 | 2011-12-25 19:23:50 +0200 | [diff] [blame^] | 37 | * @link |
Greg Aker | bde25d9 | 2010-12-21 09:31:21 -0600 | [diff] [blame] | 38 | */ |
| 39 | |
Phil Sturgeon | eb2dcda | 2011-04-02 14:44:58 +0100 | [diff] [blame] | 40 | class CI_Cache_apc extends CI_Driver { |
Greg Aker | bde25d9 | 2010-12-21 09:31:21 -0600 | [diff] [blame] | 41 | |
| 42 | /** |
Andrey Andreev | 7d4ea07 | 2011-12-25 19:23:50 +0200 | [diff] [blame^] | 43 | * Get |
Greg Aker | bde25d9 | 2010-12-21 09:31:21 -0600 | [diff] [blame] | 44 | * |
Andrey Andreev | 7d4ea07 | 2011-12-25 19:23:50 +0200 | [diff] [blame^] | 45 | * Look for a value in the cache. If it exists, return the data |
Greg Aker | bde25d9 | 2010-12-21 09:31:21 -0600 | [diff] [blame] | 46 | * if not, return FALSE |
| 47 | * |
Andrey Andreev | 7d4ea07 | 2011-12-25 19:23:50 +0200 | [diff] [blame^] | 48 | * @param string |
Greg Aker | bde25d9 | 2010-12-21 09:31:21 -0600 | [diff] [blame] | 49 | * @return mixed value that is stored/FALSE on failure |
| 50 | */ |
| 51 | public function get($id) |
| 52 | { |
| 53 | $data = apc_fetch($id); |
| 54 | |
| 55 | return (is_array($data)) ? $data[0] : FALSE; |
| 56 | } |
| 57 | |
Andrey Andreev | 7d4ea07 | 2011-12-25 19:23:50 +0200 | [diff] [blame^] | 58 | // ------------------------------------------------------------------------ |
| 59 | |
Greg Aker | bde25d9 | 2010-12-21 09:31:21 -0600 | [diff] [blame] | 60 | /** |
| 61 | * Cache Save |
| 62 | * |
| 63 | * @param string Unique Key |
| 64 | * @param mixed Data to store |
| 65 | * @param int Length of time (in seconds) to cache the data |
| 66 | * |
| 67 | * @return boolean true on success/false on failure |
| 68 | */ |
| 69 | public function save($id, $data, $ttl = 60) |
| 70 | { |
| 71 | return apc_store($id, array($data, time(), $ttl), $ttl); |
| 72 | } |
Andrey Andreev | 7d4ea07 | 2011-12-25 19:23:50 +0200 | [diff] [blame^] | 73 | |
Greg Aker | bde25d9 | 2010-12-21 09:31:21 -0600 | [diff] [blame] | 74 | // ------------------------------------------------------------------------ |
| 75 | |
| 76 | /** |
| 77 | * Delete from Cache |
| 78 | * |
| 79 | * @param mixed unique identifier of the item in the cache |
| 80 | * @param boolean true on success/false on failure |
| 81 | */ |
| 82 | public function delete($id) |
| 83 | { |
| 84 | return apc_delete($id); |
| 85 | } |
| 86 | |
| 87 | // ------------------------------------------------------------------------ |
| 88 | |
| 89 | /** |
| 90 | * Clean the cache |
| 91 | * |
| 92 | * @return boolean false on failure/true on success |
| 93 | */ |
| 94 | public function clean() |
| 95 | { |
| 96 | return apc_clear_cache('user'); |
| 97 | } |
| 98 | |
| 99 | // ------------------------------------------------------------------------ |
| 100 | |
| 101 | /** |
| 102 | * Cache Info |
| 103 | * |
| 104 | * @param string user/filehits |
Andrey Andreev | 7d4ea07 | 2011-12-25 19:23:50 +0200 | [diff] [blame^] | 105 | * @return mixed array on success, false on failure |
Greg Aker | bde25d9 | 2010-12-21 09:31:21 -0600 | [diff] [blame] | 106 | */ |
| 107 | public function cache_info($type = NULL) |
| 108 | { |
| 109 | return apc_cache_info($type); |
| 110 | } |
| 111 | |
| 112 | // ------------------------------------------------------------------------ |
| 113 | |
| 114 | /** |
| 115 | * Get Cache Metadata |
| 116 | * |
| 117 | * @param mixed key to get cache metadata on |
| 118 | * @return mixed array on success/false on failure |
| 119 | */ |
| 120 | public function get_metadata($id) |
| 121 | { |
| 122 | $stored = apc_fetch($id); |
| 123 | |
| 124 | if (count($stored) !== 3) |
| 125 | { |
| 126 | return FALSE; |
| 127 | } |
| 128 | |
Greg Aker | 999e747 | 2011-01-29 16:16:58 -0600 | [diff] [blame] | 129 | list($data, $time, $ttl) = $stored; |
Greg Aker | bde25d9 | 2010-12-21 09:31:21 -0600 | [diff] [blame] | 130 | |
| 131 | return array( |
| 132 | 'expire' => $time + $ttl, |
| 133 | 'mtime' => $time, |
| 134 | 'data' => $data |
| 135 | ); |
| 136 | } |
| 137 | |
| 138 | // ------------------------------------------------------------------------ |
| 139 | |
| 140 | /** |
| 141 | * is_supported() |
| 142 | * |
| 143 | * Check to see if APC is available on this system, bail if it isn't. |
| 144 | */ |
| 145 | public function is_supported() |
| 146 | { |
Bo-Yi Wu | 4d7c27e | 2011-10-15 12:02:32 +0800 | [diff] [blame] | 147 | if ( ! extension_loaded('apc') OR ini_get('apc.enabled') != "1") |
Greg Aker | bde25d9 | 2010-12-21 09:31:21 -0600 | [diff] [blame] | 148 | { |
| 149 | log_message('error', 'The APC PHP extension must be loaded to use APC Cache.'); |
| 150 | return FALSE; |
| 151 | } |
Andrey Andreev | 7d4ea07 | 2011-12-25 19:23:50 +0200 | [diff] [blame^] | 152 | |
Greg Aker | bde25d9 | 2010-12-21 09:31:21 -0600 | [diff] [blame] | 153 | return TRUE; |
| 154 | } |
| 155 | |
| 156 | // ------------------------------------------------------------------------ |
| 157 | |
Andrey Andreev | 7d4ea07 | 2011-12-25 19:23:50 +0200 | [diff] [blame^] | 158 | |
Greg Aker | bde25d9 | 2010-12-21 09:31:21 -0600 | [diff] [blame] | 159 | } |
| 160 | // End Class |
| 161 | |
| 162 | /* End of file Cache_apc.php */ |
Bo-Yi Wu | 4d7c27e | 2011-10-15 12:02:32 +0800 | [diff] [blame] | 163 | /* Location: ./system/libraries/Cache/drivers/Cache_apc.php */ |