protected function cache($task, $data = null)
    {
        $config = array_merge($this->cache, $task['cache']);
        if (! $config['enable']) {
            return null;
        }
        if (! isset($config['dir'])) {
            user_error('cache dir is not defined', E_USER_WARNING);
            return null;
        }
        $url = $task['opt'][CURLOPT_URL];
        $post = null;
        if (true == $config['verifyPost'] && ! empty($task['opt'][CURLOPT_POSTFIELDS])) {
            $post = $task['opt'][CURLOPT_POSTFIELDS];
        }
        $file = rtrim($config['dir'], '/') . '/';
        $file .= $this->getCacheFile($url, $post);
        if (! isset($data)) {
            if (file_exists($file)) {
                $time = time();
                $mtime = filemtime($file);
                if ($time - $mtime < $config['expire']) {
                    return unserialize(gzuncompress(file_get_contents($file)));
                }
            }
        } else {
            if (! isset($data['cache'])) {
                $data['cache'] = array();
            }
            $data['cacheFile'] = $file;
            unset($data['curl']);
            $dir = dirname($file);
            $dir1 = dirname($dir);
            if (! is_dir($dir1)) {
                mkdir($dir1);
            }
            if (! is_dir($dir)) {
                mkdir($dir);
            }
            // Cache response from downloaded file.
            if (isset($task['fileMeta']['uri'])) {
                $data['body'] = file_get_contents($task['fileMeta']['uri']);
            }
            file_put_contents($file, gzcompress(serialize($data), $config['compress']), LOCK_EX);
        }
        return null;
    }