blob: de75719c4175a56e8c4a65b4306565aa05e219c4 [file] [log] [blame]
Greg Akerbde25d92010-12-21 09:31:21 -06001<?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 ExpressionEngine Dev Team
Derek Jones700205a2011-01-28 07:44:28 -06009 * @copyright Copyright (c) 2006 - 2011 EllisLab, Inc.
Greg Akerbde25d92010-12-21 09:31:21 -060010 * @license http://codeigniter.com/user_guide/license.html
11 * @link http://codeigniter.com
12 * @since Version 2.0
Derek Jones4b9c6292011-07-01 17:40:48 -050013 * @filesource
Greg Akerbde25d92010-12-21 09:31:21 -060014 */
15
16// ------------------------------------------------------------------------
17
18/**
Derek Jones4b9c6292011-07-01 17:40:48 -050019 * CodeIgniter APC Caching Class
Greg Akerbde25d92010-12-21 09:31:21 -060020 *
21 * @package CodeIgniter
22 * @subpackage Libraries
23 * @category Core
24 * @author ExpressionEngine Dev Team
Derek Jones4b9c6292011-07-01 17:40:48 -050025 * @link
Greg Akerbde25d92010-12-21 09:31:21 -060026 */
27
Phil Sturgeoneb2dcda2011-04-02 14:44:58 +010028class CI_Cache_apc extends CI_Driver {
Greg Akerbde25d92010-12-21 09:31:21 -060029
30 /**
Derek Jones4b9c6292011-07-01 17:40:48 -050031 * Get
Greg Akerbde25d92010-12-21 09:31:21 -060032 *
Derek Jones4b9c6292011-07-01 17:40:48 -050033 * Look for a value in the cache. If it exists, return the data
Greg Akerbde25d92010-12-21 09:31:21 -060034 * if not, return FALSE
35 *
Derek Jones4b9c6292011-07-01 17:40:48 -050036 * @param string
Greg Akerbde25d92010-12-21 09:31:21 -060037 * @return mixed value that is stored/FALSE on failure
38 */
39 public function get($id)
40 {
41 $data = apc_fetch($id);
42
43 return (is_array($data)) ? $data[0] : FALSE;
44 }
45
Derek Jones4b9c6292011-07-01 17:40:48 -050046 // ------------------------------------------------------------------------
47
Greg Akerbde25d92010-12-21 09:31:21 -060048 /**
49 * Cache Save
50 *
51 * @param string Unique Key
52 * @param mixed Data to store
53 * @param int Length of time (in seconds) to cache the data
54 *
55 * @return boolean true on success/false on failure
56 */
57 public function save($id, $data, $ttl = 60)
58 {
59 return apc_store($id, array($data, time(), $ttl), $ttl);
60 }
Derek Jones4b9c6292011-07-01 17:40:48 -050061
Greg Akerbde25d92010-12-21 09:31:21 -060062 // ------------------------------------------------------------------------
63
64 /**
65 * Delete from Cache
66 *
67 * @param mixed unique identifier of the item in the cache
68 * @param boolean true on success/false on failure
69 */
70 public function delete($id)
71 {
72 return apc_delete($id);
73 }
74
75 // ------------------------------------------------------------------------
76
77 /**
78 * Clean the cache
79 *
80 * @return boolean false on failure/true on success
81 */
82 public function clean()
83 {
84 return apc_clear_cache('user');
85 }
86
87 // ------------------------------------------------------------------------
88
89 /**
90 * Cache Info
91 *
92 * @param string user/filehits
Derek Jones4b9c6292011-07-01 17:40:48 -050093 * @return mixed array on success, false on failure
Greg Akerbde25d92010-12-21 09:31:21 -060094 */
95 public function cache_info($type = NULL)
96 {
97 return apc_cache_info($type);
98 }
99
100 // ------------------------------------------------------------------------
101
102 /**
103 * Get Cache Metadata
104 *
105 * @param mixed key to get cache metadata on
106 * @return mixed array on success/false on failure
107 */
108 public function get_metadata($id)
109 {
110 $stored = apc_fetch($id);
111
112 if (count($stored) !== 3)
113 {
114 return FALSE;
115 }
116
Greg Aker999e7472011-01-29 16:16:58 -0600117 list($data, $time, $ttl) = $stored;
Greg Akerbde25d92010-12-21 09:31:21 -0600118
119 return array(
120 'expire' => $time + $ttl,
121 'mtime' => $time,
122 'data' => $data
123 );
124 }
125
126 // ------------------------------------------------------------------------
127
128 /**
129 * is_supported()
130 *
131 * Check to see if APC is available on this system, bail if it isn't.
132 */
133 public function is_supported()
134 {
135 if ( ! extension_loaded('apc') OR ! function_exists('apc_store'))
136 {
137 log_message('error', 'The APC PHP extension must be loaded to use APC Cache.');
138 return FALSE;
139 }
Derek Jones4b9c6292011-07-01 17:40:48 -0500140
Greg Akerbde25d92010-12-21 09:31:21 -0600141 return TRUE;
142 }
143
144 // ------------------------------------------------------------------------
145
Derek Jones4b9c6292011-07-01 17:40:48 -0500146
Greg Akerbde25d92010-12-21 09:31:21 -0600147}
148// End Class
149
150/* End of file Cache_apc.php */
151/* Location: ./system/libraries/Cache/drivers/Cache_apc.php */