1
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
5
* An open source application development framework for PHP 4.3.2 or newer
8
* @author ExpressionEngine Dev Team
9
* @copyright Copyright (c) 2006 - 2012 EllisLab, Inc.
10
* @license http://codeigniter.com/user_guide/license.html
11
* @link http://codeigniter.com
16
// ------------------------------------------------------------------------
19
* CodeIgniter Caching Class
21
* @package CodeIgniter
22
* @subpackage Libraries
24
* @author ExpressionEngine Dev Team
27
class CI_Cache extends CI_Driver_Library {
29
protected $valid_drivers = array(
30
'cache_apc', 'cache_file', 'cache_memcached', 'cache_dummy'
33
protected $_cache_path = NULL; // Path of cache files (if file-based cache)
34
protected $_adapter = 'dummy';
35
protected $_backup_driver;
37
// ------------------------------------------------------------------------
44
public function __construct($config = array())
46
if ( ! empty($config))
48
$this->_initialize($config);
52
// ------------------------------------------------------------------------
57
* Look for a value in the cache. If it exists, return the data
58
* if not, return FALSE
61
* @return mixed value that is stored/FALSE on failure
63
public function get($id)
65
return $this->{$this->_adapter}->get($id);
68
// ------------------------------------------------------------------------
73
* @param string Unique Key
74
* @param mixed Data to store
75
* @param int Length of time (in seconds) to cache the data
77
* @return boolean true on success/false on failure
79
public function save($id, $data, $ttl = 60)
81
return $this->{$this->_adapter}->save($id, $data, $ttl);
84
// ------------------------------------------------------------------------
89
* @param mixed unique identifier of the item in the cache
90
* @return boolean true on success/false on failure
92
public function delete($id)
94
return $this->{$this->_adapter}->delete($id);
97
// ------------------------------------------------------------------------
102
* @return boolean false on failure/true on success
104
public function clean()
106
return $this->{$this->_adapter}->clean();
109
// ------------------------------------------------------------------------
114
* @param string user/filehits
115
* @return mixed array on success, false on failure
117
public function cache_info($type = 'user')
119
return $this->{$this->_adapter}->cache_info($type);
122
// ------------------------------------------------------------------------
127
* @param mixed key to get cache metadata on
128
* @return mixed return value from child method
130
public function get_metadata($id)
132
return $this->{$this->_adapter}->get_metadata($id);
135
// ------------------------------------------------------------------------
140
* Initialize class properties based on the configuration array.
145
private function _initialize($config)
147
$default_config = array(
152
foreach ($default_config as $key)
154
if (isset($config[$key]))
158
$this->{$param} = $config[$key];
162
if (isset($config['backup']))
164
if (in_array('cache_'.$config['backup'], $this->valid_drivers))
166
$this->_backup_driver = $config['backup'];
171
// ------------------------------------------------------------------------
174
* Is the requested driver supported in this environment?
176
* @param string The driver to test.
179
public function is_supported($driver)
181
static $support = array();
183
if ( ! isset($support[$driver]))
185
$support[$driver] = $this->{$driver}->is_supported();
188
return $support[$driver];
191
// ------------------------------------------------------------------------
199
public function __get($child)
201
$obj = parent::__get($child);
203
if ( ! $this->is_supported($child))
205
$this->_adapter = $this->_backup_driver;
211
// ------------------------------------------------------------------------
215
/* End of file Cache.php */
216
/* Location: ./system/libraries/Cache/Cache.php */
b'\\ No newline at end of file'