KumbiaPHP beta2-dev
Framework PHP en español
|
00001 <?php 00027 abstract class Cache 00028 { 00034 protected static $_drivers = array(); 00035 00041 protected static $_default_driver = 'file'; 00042 00048 protected $_id = null; 00049 00055 protected $_group = 'default'; 00056 00062 protected $_lifetime = null; 00063 00071 public abstract function get($id, $group = 'default'); 00072 00082 public abstract function save ($value, $lifetime = NULL, $id = FALSE, $group = 'default'); 00083 00090 public abstract function clean ($group=false); 00091 00099 public abstract function remove($id, $group = 'default'); 00100 00109 public function start ($lifetime, $id, $group = 'default') 00110 { 00111 if ($data = $this->get($id, $group)) { 00112 echo $data; 00113 00114 // No es necesario cachear 00115 return FALSE; 00116 } 00117 $this->_lifetime = $lifetime; 00118 00119 // inicia la captura del buffer 00120 ob_start(); 00121 00122 // Inicia cacheo 00123 return TRUE; 00124 } 00125 00132 public function end ($save = TRUE) 00133 { 00134 if (! $save) { 00135 ob_end_flush(); 00136 return FALSE; 00137 } 00138 00139 // obtiene el contenido del buffer 00140 $value = ob_get_contents(); 00141 00142 // libera el buffer 00143 ob_end_flush(); 00144 00145 return $this->save($value, $this->_lifetime, $this->_id, $this->_group); 00146 } 00147 00153 public static function driver($driver = NULL) 00154 { 00155 if(! $driver) { 00156 $driver = self::$_default_driver; 00157 } 00158 00159 if(!isset(self::$_drivers[$driver])) { 00160 require_once CORE_PATH . "libs/cache/drivers/{$driver}_cache.php"; 00161 $class = $driver.'cache'; 00162 self::$_drivers[$driver] = new $class(); 00163 } 00164 00165 return self::$_drivers[$driver]; 00166 } 00167 00173 public static function setDefault ($driver = 'file') 00174 { 00175 self::$_default_driver = $driver; 00176 } 00177 }