KumbiaPHP  beta2
Framework PHP
 Todo Estructuras de Datos Namespaces Archivos Funciones Variables Páginas
cache.php
Ir a la documentación de este archivo.
1 <?php
27 abstract class Cache
28 {
29 
35  protected static $_drivers = array();
41  protected static $_default_driver = 'file';
47  protected $_id = null;
53  protected $_group = 'default';
59  protected $_lifetime = null;
60 
68  public abstract function get($id, $group = 'default');
69 
79  public abstract function save($value, $lifetime = NULL, $id = FALSE, $group = 'default');
80 
87  public abstract function clean($group=false);
88 
96  public abstract function remove($id, $group = 'default');
97 
106  public function start($lifetime, $id, $group = 'default')
107  {
108  if ($data = $this->get($id, $group)) {
109  echo $data;
110 
111  // No es necesario cachear
112  return FALSE;
113  }
114  $this->_lifetime = $lifetime;
115 
116  // inicia la captura del buffer
117  ob_start();
118 
119  // Inicia cacheo
120  return TRUE;
121  }
122 
129  public function end($save = TRUE)
130  {
131  if (!$save) {
132  ob_end_flush();
133  return FALSE;
134  }
135 
136  // obtiene el contenido del buffer
137  $value = ob_get_contents();
138 
139  // libera el buffer
140  ob_end_flush();
141 
142  return $this->save($value, $this->_lifetime, $this->_id, $this->_group);
143  }
144 
150  public static function driver($driver = NULL)
151  {
152  if (!$driver) {
153  $driver = self::$_default_driver;
154  }
155 
156  if (!isset(self::$_drivers[$driver])) {
157  require_once CORE_PATH . "libs/cache/drivers/{$driver}_cache.php";
158  $class = $driver . 'cache';
159  self::$_drivers[$driver] = new $class();
160  }
161 
162  return self::$_drivers[$driver];
163  }
164 
170  public static function setDefault($driver = 'file')
171  {
172  self::$_default_driver = $driver;
173  }
174 
175 }