protected function saveToCache(array $data)
    {
        $cacheDir = dirname($this->cacheFile);

        if (! is_dir($cacheDir) || ! is_writable($cacheDir)) {
            throw new \RuntimeException(sprintf(
                'Invalid cache directory "%s": directory does not exist or not writable.',
                $cacheDir
            ));
        }

        return file_put_contents(
            $this->cacheFile,
            '<?php return ' . var_export($data, true) . ';'
        );
    }