blob: a3dd469786f9766492bf42d3edc250da167a80ee [file] [log] [blame]
Andrey Andreev7d4ea072011-12-25 19:23:50 +02001<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
Greg Akerbde25d92010-12-21 09:31:21 -06002/**
3 * CodeIgniter
4 *
5 * An open source application development framework for PHP 5.1.6 or newer
6 *
Derek Jonesf4a4bd82011-10-20 12:18:42 -05007 * NOTICE OF LICENSE
Andrey Andreev7d4ea072011-12-25 19:23:50 +02008 *
Derek Jonesf4a4bd82011-10-20 12:18:42 -05009 * Licensed under the Open Software License version 3.0
Andrey Andreev7d4ea072011-12-25 19:23:50 +020010 *
Derek Jonesf4a4bd82011-10-20 12:18:42 -050011 * 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 Akerbde25d92010-12-21 09:31:21 -060019 * @package CodeIgniter
Derek Jonesf4a4bd82011-10-20 12:18:42 -050020 * @author EllisLab Dev Team
Greg Aker0defe5d2012-01-01 18:46:41 -060021 * @copyright Copyright (c) 2006 - 2012 EllisLab, Inc.
Derek Jonesf4a4bd82011-10-20 12:18:42 -050022 * @license http://opensource.org/licenses/OSL-3.0 Open Software License (OSL 3.0)
Greg Akerbde25d92010-12-21 09:31:21 -060023 * @link http://codeigniter.com
24 * @since Version 2.0
Andrey Andreev7d4ea072011-12-25 19:23:50 +020025 * @filesource
Greg Akerbde25d92010-12-21 09:31:21 -060026 */
27
28// ------------------------------------------------------------------------
29
30/**
Andrey Andreev7d4ea072011-12-25 19:23:50 +020031 * CodeIgniter APC Caching Class
Greg Akerbde25d92010-12-21 09:31:21 -060032 *
33 * @package CodeIgniter
34 * @subpackage Libraries
35 * @category Core
Derek Jonesf4a4bd82011-10-20 12:18:42 -050036 * @author EllisLab Dev Team
Andrey Andreev7d4ea072011-12-25 19:23:50 +020037 * @link
Greg Akerbde25d92010-12-21 09:31:21 -060038 */
39
Phil Sturgeoneb2dcda2011-04-02 14:44:58 +010040class CI_Cache_apc extends CI_Driver {
Greg Akerbde25d92010-12-21 09:31:21 -060041
42 /**
Andrey Andreev7d4ea072011-12-25 19:23:50 +020043 * Get
Greg Akerbde25d92010-12-21 09:31:21 -060044 *
Andrey Andreev7d4ea072011-12-25 19:23:50 +020045 * Look for a value in the cache. If it exists, return the data
Greg Akerbde25d92010-12-21 09:31:21 -060046 * if not, return FALSE
47 *
Andrey Andreev7d4ea072011-12-25 19:23:50 +020048 * @param string
Greg Akerbde25d92010-12-21 09:31:21 -060049 * @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 Andreev7d4ea072011-12-25 19:23:50 +020058 // ------------------------------------------------------------------------
59
Greg Akerbde25d92010-12-21 09:31:21 -060060 /**
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 {
Sean Fisher7bb95df2012-01-16 09:23:14 -050071 $ttl = (int) $ttl;
Greg Akerbde25d92010-12-21 09:31:21 -060072 return apc_store($id, array($data, time(), $ttl), $ttl);
73 }
Andrey Andreev7d4ea072011-12-25 19:23:50 +020074
Greg Akerbde25d92010-12-21 09:31:21 -060075 // ------------------------------------------------------------------------
76
77 /**
78 * Delete from Cache
79 *
80 * @param mixed unique identifier of the item in the cache
81 * @param boolean true on success/false on failure
82 */
83 public function delete($id)
84 {
85 return apc_delete($id);
86 }
87
88 // ------------------------------------------------------------------------
89
90 /**
91 * Clean the cache
92 *
93 * @return boolean false on failure/true on success
94 */
95 public function clean()
96 {
97 return apc_clear_cache('user');
98 }
99
100 // ------------------------------------------------------------------------
101
102 /**
103 * Cache Info
104 *
105 * @param string user/filehits
Andrey Andreev7d4ea072011-12-25 19:23:50 +0200106 * @return mixed array on success, false on failure
Greg Akerbde25d92010-12-21 09:31:21 -0600107 */
108 public function cache_info($type = NULL)
109 {
110 return apc_cache_info($type);
111 }
112
113 // ------------------------------------------------------------------------
114
115 /**
116 * Get Cache Metadata
117 *
118 * @param mixed key to get cache metadata on
119 * @return mixed array on success/false on failure
120 */
121 public function get_metadata($id)
122 {
123 $stored = apc_fetch($id);
124
125 if (count($stored) !== 3)
126 {
127 return FALSE;
128 }
129
Greg Aker999e7472011-01-29 16:16:58 -0600130 list($data, $time, $ttl) = $stored;
Greg Akerbde25d92010-12-21 09:31:21 -0600131
132 return array(
133 'expire' => $time + $ttl,
134 'mtime' => $time,
135 'data' => $data
136 );
137 }
138
139 // ------------------------------------------------------------------------
140
141 /**
142 * is_supported()
143 *
144 * Check to see if APC is available on this system, bail if it isn't.
145 */
146 public function is_supported()
147 {
Bo-Yi Wu4d7c27e2011-10-15 12:02:32 +0800148 if ( ! extension_loaded('apc') OR ini_get('apc.enabled') != "1")
Greg Akerbde25d92010-12-21 09:31:21 -0600149 {
150 log_message('error', 'The APC PHP extension must be loaded to use APC Cache.');
151 return FALSE;
152 }
Andrey Andreev7d4ea072011-12-25 19:23:50 +0200153
Greg Akerbde25d92010-12-21 09:31:21 -0600154 return TRUE;
155 }
156
157 // ------------------------------------------------------------------------
158
Andrey Andreev7d4ea072011-12-25 19:23:50 +0200159
Greg Akerbde25d92010-12-21 09:31:21 -0600160}
161// End Class
162
163/* End of file Cache_apc.php */
Bo-Yi Wu4d7c27e2011-10-15 12:02:32 +0800164/* Location: ./system/libraries/Cache/drivers/Cache_apc.php */