import Storage from "./../Storage";

// Clear all caches named cacheName:xx
function clearCache(cacheName) {
  var _ref = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {},
    match = _ref.match;
  delete window[cacheName];
  Storage.removeLocalStorage(cacheName);

  // 清除所有以 cache: 开头的属性
  if (match === 'prefix') {
    for (var keyName in window) {
      if (window.hasOwnProperty(keyName) && keyName.startsWith("".concat(cacheName, ":"))) {
        delete window[keyName];
      }
    }

    // 清除所有以 cache: 开头的项
    Storage.removeLocalStorages(function (keyName) {
      return keyName.startsWith("".concat(cacheName, ":"));
    });
    Storage.removeSessionStorages(function (keyName) {
      return keyName.startsWith("".concat(cacheName, ":"));
    });
  }
}
export default clearCache;