blob: c85034f952dec67489fac32ea82326a35f9c79ba [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 *
Phil Sturgeon07c1ac82012-03-09 17:03:37 +00005 * An open source application development framework for PHP 5.2.4 or newer
Greg Akerbde25d92010-12-21 09:31:21 -06006 *
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
Greg Akerbde25d92010-12-21 09:31:21 -060028/**
Andrey Andreev7d4ea072011-12-25 19:23:50 +020029 * CodeIgniter APC Caching Class
Greg Akerbde25d92010-12-21 09:31:21 -060030 *
31 * @package CodeIgniter
32 * @subpackage Libraries
33 * @category Core
Derek Jonesf4a4bd82011-10-20 12:18:42 -050034 * @author EllisLab Dev Team
Andrey Andreev7d4ea072011-12-25 19:23:50 +020035 * @link
Greg Akerbde25d92010-12-21 09:31:21 -060036 */
Phil Sturgeoneb2dcda2011-04-02 14:44:58 +010037class CI_Cache_apc extends CI_Driver {
Greg Akerbde25d92010-12-21 09:31:21 -060038
39 /**
Andrey Andreev7d4ea072011-12-25 19:23:50 +020040 * Get
Greg Akerbde25d92010-12-21 09:31:21 -060041 *
Andrey Andreevb24b0332012-03-26 15:34:39 +030042 * Look for a value in the cache. If it exists, return the data
Greg Akerbde25d92010-12-21 09:31:21 -060043 * if not, return FALSE
44 *
Andrey Andreevb24b0332012-03-26 15:34:39 +030045 * @param string
46 * @return mixed value that is stored/FALSE on failure
Greg Akerbde25d92010-12-21 09:31:21 -060047 */
48 public function get($id)
49 {
50 $data = apc_fetch($id);
51
Andrey Andreevb24b0332012-03-26 15:34:39 +030052 return is_array($data) ? $data[0] : FALSE;
Greg Akerbde25d92010-12-21 09:31:21 -060053 }
54
Andrey Andreev7d4ea072011-12-25 19:23:50 +020055 // ------------------------------------------------------------------------
56
Greg Akerbde25d92010-12-21 09:31:21 -060057 /**
58 * Cache Save
59 *
Andrey Andreevb24b0332012-03-26 15:34:39 +030060 * @param string Unique Key
61 * @param mixed Data to store
62 * @param int Length of time (in seconds) to cache the data
Greg Akerbde25d92010-12-21 09:31:21 -060063 *
Andrey Andreevb24b0332012-03-26 15:34:39 +030064 * @return bool true on success/false on failure
Greg Akerbde25d92010-12-21 09:31:21 -060065 */
66 public function save($id, $data, $ttl = 60)
67 {
Sean Fisher7bb95df2012-01-16 09:23:14 -050068 $ttl = (int) $ttl;
Greg Akerbde25d92010-12-21 09:31:21 -060069 return apc_store($id, array($data, time(), $ttl), $ttl);
70 }
Andrey Andreev7d4ea072011-12-25 19:23:50 +020071
Greg Akerbde25d92010-12-21 09:31:21 -060072 // ------------------------------------------------------------------------
73
74 /**
75 * Delete from Cache
76 *
Andrey Andreevb24b0332012-03-26 15:34:39 +030077 * @param mixed unique identifier of the item in the cache
Timothy Warren0688ac92012-04-20 10:25:04 -040078 * @return bool true on success/false on failure
Greg Akerbde25d92010-12-21 09:31:21 -060079 */
80 public function delete($id)
81 {
82 return apc_delete($id);
83 }
84
85 // ------------------------------------------------------------------------
86
87 /**
88 * Clean the cache
89 *
Andrey Andreevb24b0332012-03-26 15:34:39 +030090 * @return bool false on failure/true on success
Greg Akerbde25d92010-12-21 09:31:21 -060091 */
92 public function clean()
93 {
94 return apc_clear_cache('user');
95 }
96
97 // ------------------------------------------------------------------------
98
99 /**
100 * Cache Info
101 *
Andrey Andreevb24b0332012-03-26 15:34:39 +0300102 * @param string user/filehits
103 * @return mixed array on success, false on failure
Greg Akerbde25d92010-12-21 09:31:21 -0600104 */
105 public function cache_info($type = NULL)
106 {
107 return apc_cache_info($type);
108 }
109
110 // ------------------------------------------------------------------------
111
112 /**
113 * Get Cache Metadata
114 *
Andrey Andreevb24b0332012-03-26 15:34:39 +0300115 * @param mixed key to get cache metadata on
116 * @return mixed array on success/false on failure
Greg Akerbde25d92010-12-21 09:31:21 -0600117 */
118 public function get_metadata($id)
119 {
120 $stored = apc_fetch($id);
121
122 if (count($stored) !== 3)
123 {
124 return FALSE;
125 }
126
Greg Aker999e7472011-01-29 16:16:58 -0600127 list($data, $time, $ttl) = $stored;
Greg Akerbde25d92010-12-21 09:31:21 -0600128
129 return array(
130 'expire' => $time + $ttl,
131 'mtime' => $time,
132 'data' => $data
133 );
134 }
135
136 // ------------------------------------------------------------------------
137
138 /**
139 * is_supported()
140 *
141 * Check to see if APC is available on this system, bail if it isn't.
Andrey Andreevb24b0332012-03-26 15:34:39 +0300142 *
143 * @return bool
Greg Akerbde25d92010-12-21 09:31:21 -0600144 */
145 public function is_supported()
146 {
Andrey Andreevb24b0332012-03-26 15:34:39 +0300147 if ( ! extension_loaded('apc') OR ! (bool) @ini_get('apc.enabled'))
Greg Akerbde25d92010-12-21 09:31:21 -0600148 {
149 log_message('error', 'The APC PHP extension must be loaded to use APC Cache.');
150 return FALSE;
151 }
Andrey Andreev7d4ea072011-12-25 19:23:50 +0200152
Greg Akerbde25d92010-12-21 09:31:21 -0600153 return TRUE;
154 }
155
Greg Akerbde25d92010-12-21 09:31:21 -0600156}
Greg Akerbde25d92010-12-21 09:31:21 -0600157
158/* End of file Cache_apc.php */
Andrey Andreevb24b0332012-03-26 15:34:39 +0300159/* Location: ./system/libraries/Cache/drivers/Cache_apc.php */