Remove file execution permission.
[living-lab-site.git] / system / libraries / Cache / drivers / Cache_apc.php
1 <?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
9  * @copyright   Copyright (c) 2006 - 2011 EllisLab, Inc.
10  * @license             http://codeigniter.com/user_guide/license.html
11  * @link                http://codeigniter.com
12  * @since               Version 2.0
13  * @filesource  
14  */
15
16 // ------------------------------------------------------------------------
17
18 /**
19  * CodeIgniter APC Caching Class 
20  *
21  * @package             CodeIgniter
22  * @subpackage  Libraries
23  * @category    Core
24  * @author              ExpressionEngine Dev Team
25  * @link                
26  */
27
28 class CI_Cache_apc extends CI_Driver {
29
30         /**
31          * Get 
32          *
33          * Look for a value in the cache.  If it exists, return the data 
34          * if not, return FALSE
35          *
36          * @param       string  
37          * @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
46         // ------------------------------------------------------------------------     
47         
48         /**
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         }
61         
62         // ------------------------------------------------------------------------
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
93          * @return      mixed           array on success, false on failure      
94          */
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
117                 list($data, $time, $ttl) = $stored;
118
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                 }
140                 
141                 return TRUE;
142         }
143
144         // ------------------------------------------------------------------------
145
146         
147 }
148 // End Class
149
150 /* End of file Cache_apc.php */
151 /* Location: ./system/libraries/Cache/drivers/Cache_apc.php */