export default function(get, regexes) {
  // cachingGet
  const cache = new Map();

  return function cachedGet(url) {
    const key = url;

    if (regexes.some(regex => url.match(regex))) {
      if (cache.has(key)) {
        const request = cache.get(key);
        // console.log("cache.get(key):" + request.then(v => console.log(v)));
        return request;
      } else {
        const request = get(...arguments);
        return request.then(v => {
          if (v.status === 200) {
            // 如果能取到数据，才缓存
            cache.set(key, request);
          }
          return request;
        });

        // return request;
      }
    } else {
      const request = get(...arguments);
      return request;
    }
  };
}
