protected function cache($name, $data = null, $lifetime = null)
	{
		// Cache file is a hash of the name
		$file = $name.'.pathcache';

		// Cache directories are split by keys to prevent filesystem overload
		$dir = rtrim($this->cache_dir, DS).DS;

		if ($lifetime === NULL)
		{
			// Use the default lifetime
			$lifetime = $this->cache_lifetime;
		}

		if ($data === null)
		{
			if (is_file($dir.$file))
			{
				if ((time() - filemtime($dir.$file)) < $lifetime)
				{
					// Return the cache
					try
					{
						return unserialize(file_get_contents($dir.$file));
					}
					catch (\Exception $e)
					{
						// Cache exists but could not be read, ignore it
					}
				}
				else
				{
					try
					{
						// Cache has expired
						unlink($dir.$file);
					}
					catch (Exception $e)
					{
						// Cache has mostly likely already been deleted,
						// let return happen normally.
					}
				}
			}

			// Cache not found
			return null;
		}

		if ( ! is_dir($dir))
		{
			// Create the cache directory
			mkdir($dir, \Config::get('file.chmod.folders', 0777), true);

			// Set permissions (must be manually set to fix umask issues)
			chmod($dir, \Config::get('file.chmod.folders', 0777));
		}

		// Force the data to be a string
		$data = serialize($data);

		try
		{
			// Write the cache, and set permissions
			if ($result = (bool) file_put_contents($dir.$file, $data, LOCK_EX))
			{
				try
				{
					chmod($dir.$file, \Config::get('file.chmod.files', 0666));
				}
				catch (\PhpErrorException $e)
				{
					// if we get something else then a chmod error, bail out
					if (substr($e->getMessage(),0,8) !== 'chmod():')
					{
						throw new $e;
					}
				}
			}

			return $result;
		}
		catch (\Exception $e)
		{
			// Failed to write cache
			return false;
		}
	}