From 12fe58d997d2066dc362fd393a18b4e5da190513 Mon Sep 17 00:00:00 2001 From: Bharat Mediratta Date: Wed, 27 May 2009 15:11:53 -0700 Subject: Rename 'kohana' to 'system' to conform to the Kohana filesystem layout. I'm comfortable with us not clearly drawing the distinction about the fact that it's Kohana. --- kohana/libraries/Cache.php | 208 --------------------------------------------- 1 file changed, 208 deletions(-) delete mode 100644 kohana/libraries/Cache.php (limited to 'kohana/libraries/Cache.php') diff --git a/kohana/libraries/Cache.php b/kohana/libraries/Cache.php deleted file mode 100644 index 8a02a905..00000000 --- a/kohana/libraries/Cache.php +++ /dev/null @@ -1,208 +0,0 @@ -config = $config; - - // Set driver name - $driver = 'Cache_'.ucfirst($this->config['driver']).'_Driver'; - - // Load the driver - if ( ! Kohana::auto_load($driver)) - throw new Kohana_Exception('core.driver_not_found', $this->config['driver'], get_class($this)); - - // Initialize the driver - $this->driver = new $driver($this->config['params']); - - // Validate the driver - 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) - { - // Do garbage collection - $this->driver->delete_expired(); - - Kohana::log('debug', 'Cache: Expired caches deleted.'); - } - - // Cache has been loaded once - Cache::$loaded = TRUE; - } - } - - /** - * Fetches a cache by id. NULL is returned when a cache item is not found. - * - * @param string cache id - * @return mixed cached data or NULL - */ - public function get($id) - { - // Sanitize the ID - $id = $this->sanitize_id($id); - - return $this->driver->get($id); - } - - /** - * Fetches all of the caches for a given tag. An empty array will be - * returned when no matching caches are found. - * - * @param string cache tag - * @return array all cache items matching the tag - */ - public function find($tag) - { - return $this->driver->find($tag); - } - - /** - * Set a cache item by id. Tags may also be added and a custom lifetime - * can be set. Non-string data is automatically serialized. - * - * @param string unique cache id - * @param mixed data to cache - * @param array|string tags for this item - * @param integer number of seconds until the cache expires - * @return boolean - */ - function set($id, $data, $tags = NULL, $lifetime = NULL) - { - if (is_resource($data)) - throw new Kohana_Exception('cache.resources'); - - // Sanitize the ID - $id = $this->sanitize_id($id); - - if ($lifetime === NULL) - { - // Get the default lifetime - $lifetime = $this->config['lifetime']; - } - - return $this->driver->set($id, $data, (array) $tags, $lifetime); - } - - /** - * Delete a cache item by id. - * - * @param string cache id - * @return boolean - */ - public function delete($id) - { - // Sanitize the ID - $id = $this->sanitize_id($id); - - return $this->driver->delete($id); - } - - /** - * Delete all cache items with a given tag. - * - * @param string cache tag name - * @return boolean - */ - public function delete_tag($tag) - { - return $this->driver->delete($tag, TRUE); - } - - /** - * Delete ALL cache items items. - * - * @return boolean - */ - public function delete_all() - { - return $this->driver->delete(TRUE); - } - - /** - * Replaces troublesome characters with underscores. - * - * @param string cache id - * @return string - */ - protected function sanitize_id($id) - { - // Change slashes and spaces to underscores - return str_replace(array('/', '\\', ' '), '_', $id); - } - -} // End Cache -- cgit v1.2.3