KumbiaPHP beta2-dev
Framework PHP en español
|
00001 <?php 00023 class NixfileCache extends Cache 00024 { 00030 const MAX_TIMESTAMP = 2147401800; 00031 00039 protected function _getFilename($id, $group) 00040 { 00041 return 'cache_' . md5($id) . '.' . md5($group); 00042 } 00043 00051 public function get($id, $group = 'default') 00052 { 00053 $this->_id = $id; 00054 $this->_group = $group; 00055 00056 $filename = APP_PATH . 'temp/cache/'.$this->_getFilename($id, $group); 00057 00058 if(is_file($filename) && filemtime($filename) >= time()) { 00059 return file_get_contents($filename); 00060 } 00061 00062 return null; 00063 } 00064 00074 public function save($value, $lifetime = NULL, $id = FALSE, $group = 'default') 00075 { 00076 if (! $id) { 00077 $id = $this->_id; 00078 $group = $this->_group; 00079 } 00080 00081 if ($lifetime) { 00082 $lifetime = strtotime($lifetime); 00083 } else { 00084 $lifetime = self::MAX_TIMESTAMP; 00085 } 00086 00087 $filename = APP_PATH . 'temp/cache/'.$this->_getFilename($id, $group); 00088 00089 // Almacena en la fecha de modificacion la fecha de expiracion 00090 return file_put_contents($filename, $value) && touch($filename, $lifetime); 00091 } 00092 00099 public function clean($group = FALSE) 00100 { 00101 $pattern = $group ? APP_PATH . 'temp/cache/' . '*.' . md5($group) : APP_PATH . 'temp/cache/*'; 00102 foreach (glob($pattern) as $filename) { 00103 if(!unlink($filename)) { 00104 return false; 00105 } 00106 } 00107 return true; 00108 } 00109 00117 public function remove($id, $group = 'default') 00118 { 00119 return unlink(APP_PATH . 'temp/cache/' . $this->_getFilename($id, $group)); 00120 } 00121 }