0.2.2 • Published 2 months ago

cookie-fetch v0.2.2

Weekly downloads
-
License
MIT
Repository
github
Last release
2 months ago

cookie-fetch

npm npm

安装

使用npm

npm install cookie-fetch --save

yarn

yarn add cookie-fetch

使用示例

import CFetch, { CachePolicy } from 'cookie-fetch';

... 

async componentDidMount() {
  const url = 'http://food.boohee.com/fb/v1/categories/list';
  const options = {cache: CachePolicy.NetworkFirst, timeout: 0.1};
  try {
    const {result, isCache} = await CFetch.get(url, options);
    alert(`response: ${result} \n isCache: ${isCache}`)
  } catch (error) {
    alert(`error: ${error}`)
  }
}
  

resolve的结果为ObjectkeyresultisCache。其中result为序列化后的结果,isCache代表是否从缓存读取的结果。

缓存策略

NameDescription
NetworkFirst优先请求网络,请求失败则读取缓存,如无缓存,返回null
ForceNetwork强制请求网络,请求失败返回null
ForceCache强制读取缓存,读取失败返回null

方法

NameDescription
getGET请求方法,使用方式与fetch一致,支持在options中设置timeout
postPOST请求方法,使用方式与fetch一致,支持在options中设置timeout
clearHTTPCacheWithURL基于某个请求URL清除HTTP缓存,接受的参数与请求的URL需匹配一致,包括query部分
clearAllHTTPCache清除所有的HTTP缓存
0.2.2

2 months ago

0.2.1

6 years ago

0.2.0

6 years ago

0.1.2

6 years ago

0.1.1

6 years ago

0.1.0

6 years ago

0.0.1

6 years ago