blob: 46e633463b369aa20dd39de1051ba56b2ea1c628 [file] [log] [blame]
Andrey Andreevc5536aa2012-11-01 17:33:58 +02001<?php
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
Andrey Andreevc5536aa2012-11-01 17:33:58 +020021 * @copyright Copyright (c) 2008 - 2012, EllisLab, Inc. (http://ellislab.com/)
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 */
Andrey Andreevc5536aa2012-11-01 17:33:58 +020027defined('BASEPATH') OR exit('No direct script access allowed');
Greg Akerbde25d92010-12-21 09:31:21 -060028
Greg Akerbde25d92010-12-21 09:31:21 -060029/**
Andrey Andreev7d4ea072011-12-25 19:23:50 +020030 * CodeIgniter APC Caching Class
Greg Akerbde25d92010-12-21 09:31:21 -060031 *
32 * @package CodeIgniter
33 * @subpackage Libraries
34 * @category Core
Derek Jonesf4a4bd82011-10-20 12:18:42 -050035 * @author EllisLab Dev Team
Andrey Andreev7d4ea072011-12-25 19:23:50 +020036 * @link
Greg Akerbde25d92010-12-21 09:31:21 -060037 */
Phil Sturgeoneb2dcda2011-04-02 14:44:58 +010038class CI_Cache_apc extends CI_Driver {
Greg Akerbde25d92010-12-21 09:31:21 -060039
40 /**
Andrey Andreev7d4ea072011-12-25 19:23:50 +020041 * Get
Greg Akerbde25d92010-12-21 09:31:21 -060042 *
Andrey Andreevb24b0332012-03-26 15:34:39 +030043 * Look for a value in the cache. If it exists, return the data
Greg Akerbde25d92010-12-21 09:31:21 -060044 * if not, return FALSE
45 *
Andrey Andreevb24b0332012-03-26 15:34:39 +030046 * @param string
47 * @return mixed value that is stored/FALSE on failure
Greg Akerbde25d92010-12-21 09:31:21 -060048 */
49 public function get($id)
50 {
51 $data = apc_fetch($id);
52
Andrey Andreevb24b0332012-03-26 15:34:39 +030053 return is_array($data) ? $data[0] : FALSE;
Greg Akerbde25d92010-12-21 09:31:21 -060054 }
55
Andrey Andreev7d4ea072011-12-25 19:23:50 +020056 // ------------------------------------------------------------------------
57
Greg Akerbde25d92010-12-21 09:31:21 -060058 /**
59 * Cache Save
60 *
Andrey Andreevb24b0332012-03-26 15:34:39 +030061 * @param string Unique Key
62 * @param mixed Data to store
63 * @param int Length of time (in seconds) to cache the data
Greg Akerbde25d92010-12-21 09:31:21 -060064 *
Andrey Andreevb24b0332012-03-26 15:34:39 +030065 * @return bool true on success/false on failure
Greg Akerbde25d92010-12-21 09:31:21 -060066 */
67 public function save($id, $data, $ttl = 60)
68 {
Sean Fisher7bb95df2012-01-16 09:23:14 -050069 $ttl = (int) $ttl;
Greg Akerbde25d92010-12-21 09:31:21 -060070 return apc_store($id, array($data, time(), $ttl), $ttl);
71 }
Andrey Andreev7d4ea072011-12-25 19:23:50 +020072
Greg Akerbde25d92010-12-21 09:31:21 -060073 // ------------------------------------------------------------------------
74
75 /**
76 * Delete from Cache
77 *
Andrey Andreevb24b0332012-03-26 15:34:39 +030078 * @param mixed unique identifier of the item in the cache
Timothy Warren0688ac92012-04-20 10:25:04 -040079 * @return bool true on success/false on failure
Greg Akerbde25d92010-12-21 09:31:21 -060080 */
81 public function delete($id)
82 {
83 return apc_delete($id);
84 }
85
86 // ------------------------------------------------------------------------
87
88 /**
89 * Clean the cache
90 *
Andrey Andreevb24b0332012-03-26 15:34:39 +030091 * @return bool false on failure/true on success
Greg Akerbde25d92010-12-21 09:31:21 -060092 */
93 public function clean()
94 {
95 return apc_clear_cache('user');
96 }
97
98 // ------------------------------------------------------------------------
99
100 /**
101 * Cache Info
102 *
Andrey Andreevb24b0332012-03-26 15:34:39 +0300103 * @param string user/filehits
104 * @return mixed array on success, false on failure
Greg Akerbde25d92010-12-21 09:31:21 -0600105 */
106 public function cache_info($type = NULL)
107 {
108 return apc_cache_info($type);
109 }
110
111 // ------------------------------------------------------------------------
112
113 /**
114 * Get Cache Metadata
115 *
Andrey Andreevb24b0332012-03-26 15:34:39 +0300116 * @param mixed key to get cache metadata on
117 * @return mixed array on success/false on failure
Greg Akerbde25d92010-12-21 09:31:21 -0600118 */
119 public function get_metadata($id)
120 {
121 $stored = apc_fetch($id);
122
123 if (count($stored) !== 3)
124 {
125 return FALSE;
126 }
127
Greg Aker999e7472011-01-29 16:16:58 -0600128 list($data, $time, $ttl) = $stored;
Greg Akerbde25d92010-12-21 09:31:21 -0600129
130 return array(
131 'expire' => $time + $ttl,
132 'mtime' => $time,
133 'data' => $data
134 );
135 }
136
137 // ------------------------------------------------------------------------
138
139 /**
140 * is_supported()
141 *
142 * Check to see if APC is available on this system, bail if it isn't.
Andrey Andreevb24b0332012-03-26 15:34:39 +0300143 *
144 * @return bool
Greg Akerbde25d92010-12-21 09:31:21 -0600145 */
146 public function is_supported()
147 {
Andrey Andreevb24b0332012-03-26 15:34:39 +0300148 if ( ! extension_loaded('apc') OR ! (bool) @ini_get('apc.enabled'))
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
Greg Akerbde25d92010-12-21 09:31:21 -0600157}
Greg Akerbde25d92010-12-21 09:31:21 -0600158
159/* End of file Cache_apc.php */
Andrey Andreevb24b0332012-03-26 15:34:39 +0300160/* Location: ./system/libraries/Cache/drivers/Cache_apc.php */