blob: 90b68688dbfd002c7e6a88a829705a97a460aceb [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
Derek Jones700205a2011-01-28 07:44:28 -060021 * @copyright Copyright (c) 2006 - 2011 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 {
71 return apc_store($id, array($data, time(), $ttl), $ttl);
72 }
Andrey Andreev7d4ea072011-12-25 19:23:50 +020073
Greg Akerbde25d92010-12-21 09:31:21 -060074 // ------------------------------------------------------------------------
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 Andreev7d4ea072011-12-25 19:23:50 +0200105 * @return mixed array on success, false on failure
Greg Akerbde25d92010-12-21 09:31:21 -0600106 */
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 Aker999e7472011-01-29 16:16:58 -0600129 list($data, $time, $ttl) = $stored;
Greg Akerbde25d92010-12-21 09:31:21 -0600130
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 Wu4d7c27e2011-10-15 12:02:32 +0800147 if ( ! extension_loaded('apc') OR ini_get('apc.enabled') != "1")
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
156 // ------------------------------------------------------------------------
157
Andrey Andreev7d4ea072011-12-25 19:23:50 +0200158
Greg Akerbde25d92010-12-21 09:31:21 -0600159}
160// End Class
161
162/* End of file Cache_apc.php */
Bo-Yi Wu4d7c27e2011-10-15 12:02:32 +0800163/* Location: ./system/libraries/Cache/drivers/Cache_apc.php */