config = $config; $driver = 'Cache_'.ucfirst($this->config['driver']).'_Driver'; if ( ! Kohana::auto_load($driver)) throw new Kohana_Exception('core.driver_not_found', $this->config['driver'], get_class($this)); $this->driver = new $driver($this->config['params']); if ( ! ($this->driver instanceof Cache_Driver)) throw new Kohana_Exception('core.driver_implements', $this->config['driver'], get_class($this), 'Cache_Driver'); Kohana::log('debug', 'Cache Library initialized'); if (Cache::$loaded !== TRUE) { $this->config['requests'] = (int) $this->config['requests']; if ($this->config['requests'] > 0 AND mt_rand(1, $this->config['requests']) === 1) { $this->driver->delete_expired(); Kohana::log('debug', 'Cache: Expired caches deleted.'); } Cache::$loaded = TRUE; } } public function get($id) { $id = $this->sanitize_id($id); return $this->driver->get($id); } public function find($tag) { return $this->driver->find($tag); } function set($id, $data, $tags = NULL, $lifetime = NULL) { if (is_resource($data)) throw new Kohana_Exception('cache.resources'); $id = $this->sanitize_id($id); if ($lifetime === NULL) { $lifetime = $this->config['lifetime']; } return $this->driver->set($id, $data, (array) $tags, $lifetime); } public function delete($id) { $id = $this->sanitize_id($id); return $this->driver->delete($id); } public function delete_tag($tag) { return $this->driver->delete($tag, TRUE); } public function delete_all() { return $this->driver->delete(TRUE); } protected function sanitize_id($id) { return str_replace(array('/', '\\', ' '), '_', $id); } }