public function setCacheDirectory($directory)
    {
        if (!is_dir($directory)) {
            $this->createDirectory($directory);
        }

        if (!is_writable($directory)) {
            throw new \InvalidArgumentException(sprintf('The cache directory "%s" is not writable.', $dir));
        }

        $this->cacheDirectory = $directory;

        return $this;
    }