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 - 2011 EllisLab, Inc.
10 * @license http://codeigniter.com/user_guide/license.html
11 * @link http://codeigniter.com
16 // ------------------------------------------------------------------------
19 * CodeIgniter Memcached Caching Class
21 * @package CodeIgniter
22 * @subpackage Libraries
24 * @author ExpressionEngine Dev Team
28 class CI_Cache_file extends CI_Driver {
30 protected $_cache_path;
35 public function __construct()
37 $CI =& get_instance();
38 $CI->load->helper('file');
40 $path = $CI->config->item('cache_path');
42 $this->_cache_path = ($path == '') ? APPPATH.'cache/' : $path;
45 // ------------------------------------------------------------------------
50 * @param mixed unique key id
51 * @return mixed data on success/false on failure
53 public function get($id)
55 if ( ! file_exists($this->_cache_path.$id))
60 $data = read_file($this->_cache_path.$id);
61 $data = unserialize($data);
63 if (time() > $data['time'] + $data['ttl'])
65 unlink($this->_cache_path.$id);
72 // ------------------------------------------------------------------------
77 * @param string unique key
78 * @param mixed data to store
79 * @param int length of time (in seconds) the cache is valid
80 * - Default is 60 seconds
81 * @return boolean true on success/false on failure
83 public function save($id, $data, $ttl = 60)
91 if (write_file($this->_cache_path.$id, serialize($contents)))
93 @chmod($this->_cache_path.$id, 0777);
100 // ------------------------------------------------------------------------
105 * @param mixed unique identifier of item in cache
106 * @return boolean true on success/false on failure
108 public function delete($id)
110 return unlink($this->_cache_path.$id);
113 // ------------------------------------------------------------------------
118 * @return boolean false on failure/true on success
120 public function clean()
122 return delete_files($this->_cache_path);
125 // ------------------------------------------------------------------------
130 * Not supported by file-based caching
132 * @param string user/filehits
133 * @return mixed FALSE
135 public function cache_info($type = NULL)
137 return get_dir_file_info($this->_cache_path);
140 // ------------------------------------------------------------------------
145 * @param mixed key to get cache metadata on
146 * @return mixed FALSE on failure, array on success.
148 public function get_metadata($id)
150 if ( ! file_exists($this->_cache_path.$id))
155 $data = read_file($this->_cache_path.$id);
156 $data = unserialize($data);
160 $data = $data['data'];
161 $mtime = filemtime($this->_cache_path.$id);
163 if ( ! isset($data['ttl']))
169 'expire' => $mtime + $data['ttl'],
177 // ------------------------------------------------------------------------
182 * In the file driver, check to see that the cache directory is indeed writable
186 public function is_supported()
188 return is_really_writable($this->_cache_path);
191 // ------------------------------------------------------------------------
195 /* End of file Cache_file.php */
196 /* Location: ./system/libraries/Cache/drivers/Cache_file.php */