KumbiaPHP  beta2
Framework PHP
 Todo Estructuras de Datos Namespaces Archivos Funciones Variables Páginas
nixfile_cache.php
Ir a la documentación de este archivo.
1 <?php
29 class NixfileCache extends Cache
30 {
36  const MAX_TIMESTAMP = 2147401800;
37 
45  protected function _getFilename($id, $group)
46  {
47  return 'cache_' . md5($id) . '.' . md5($group);
48  }
49 
57  public function get($id, $group = 'default')
58  {
59  $this->_id = $id;
60  $this->_group = $group;
61 
62  $filename = APP_PATH . 'temp/cache/' . $this->_getFilename($id, $group);
63 
64  if (is_file($filename) && filemtime($filename) >= time()) {
65  return file_get_contents($filename);
66  }
67 
68  return null;
69  }
70 
80  public function save($value, $lifetime = NULL, $id = FALSE, $group = 'default')
81  {
82  if (!$id) {
83  $id = $this->_id;
84  $group = $this->_group;
85  }
86 
87  if ($lifetime) {
88  $lifetime = strtotime($lifetime);
89  } else {
90  $lifetime = self::MAX_TIMESTAMP;
91  }
92 
93  $filename = APP_PATH . 'temp/cache/' . $this->_getFilename($id, $group);
94 
95  // Almacena en la fecha de modificacion la fecha de expiracion
96  return file_put_contents($filename, $value) && touch($filename, $lifetime);
97  }
98 
105  public function clean($group = FALSE)
106  {
107  $pattern = $group ? APP_PATH . 'temp/cache/' . '*.' . md5($group) : APP_PATH . 'temp/cache/*';
108  foreach (glob($pattern) as $filename) {
109  if (!unlink($filename)) {
110  return false;
111  }
112  }
113  return true;
114  }
115 
123  public function remove($id, $group = 'default')
124  {
125  return unlink(APP_PATH . 'temp/cache/' . $this->_getFilename($id, $group));
126  }
127 
128 }