{"id":26159322,"url":"https://github.com/ljunb/cookie-fetch","last_synced_at":"2025-07-20T12:06:34.953Z","repository":{"id":92176782,"uuid":"110668077","full_name":"ljunb/cookie-fetch","owner":"ljunb","description":"应用于React Native App、支持定制简易缓存策略的fetch。","archived":false,"fork":false,"pushed_at":"2017-11-17T10:03:43.000Z","size":144,"stargazers_count":5,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-06-19T13:07:33.852Z","etag":null,"topics":["fetch","react-native"],"latest_commit_sha":null,"homepage":"","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/ljunb.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2017-11-14T09:18:45.000Z","updated_at":"2024-03-13T03:52:20.000Z","dependencies_parsed_at":null,"dependency_job_id":"b5bbfd42-ff73-4548-a120-0d7e877d7a8e","html_url":"https://github.com/ljunb/cookie-fetch","commit_stats":null,"previous_names":[],"tags_count":2,"template":false,"template_full_name":null,"purl":"pkg:github/ljunb/cookie-fetch","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ljunb%2Fcookie-fetch","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ljunb%2Fcookie-fetch/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ljunb%2Fcookie-fetch/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ljunb%2Fcookie-fetch/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ljunb","download_url":"https://codeload.github.com/ljunb/cookie-fetch/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ljunb%2Fcookie-fetch/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":266120544,"owners_count":23879337,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["fetch","react-native"],"created_at":"2025-03-11T11:21:31.706Z","updated_at":"2025-07-20T12:06:34.929Z","avatar_url":"https://github.com/ljunb.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# cookie-fetch\n\n[![npm](https://img.shields.io/npm/v/cookie-fetch.svg)](https://www.npmjs.com/package/cookie-fetch)\n[![npm](https://img.shields.io/npm/l/cookie-fetch.svg)](https://github.com/ljunb/cookie-fetch/blob/master/LICENSE)\n\n## 安装\n\n使用`npm`：\n```\nnpm install cookie-fetch --save\n```\n用`yarn`：\n```\nyarn add cookie-fetch\n```\n\n## 使用示例\n\n```\nimport CFetch, { CachePolicy } from 'cookie-fetch';\n\n... \n\nasync componentDidMount() {\n  const url = 'http://food.boohee.com/fb/v1/categories/list';\n  const options = {cache: CachePolicy.NetworkFirst, timeout: 0.1};\n  try {\n    const {result, isCache} = await CFetch.get(url, options);\n    alert(`response: ${result} \\n isCache: ${isCache}`)\n  } catch (error) {\n    alert(`error: ${error}`)\n  }\n}\n  \n```\n\n`resolve`的结果为`Object`，`key`为`result`、`isCache`。其中`result`为序列化后的结果，`isCache`代表是否从缓存读取的结果。\n\n## 缓存策略\nName            | Description\n----------------  | -----------\nNetworkFirst    | 优先请求网络，请求失败则读取缓存，如无缓存，返回`null`\nForceNetwork    | 强制请求网络，请求失败返回`null`\nForceCache      | 强制读取缓存，读取失败返回`null`\n\n## 方法\nName            | Description\n----------------  | -----------\nget    | `GET`请求方法，使用方式与`fetch`一致，支持在`options`中设置`timeout`\npost    | `POST`请求方法，使用方式与`fetch`一致，支持在`options`中设置`timeout`\nclearHTTPCacheWithURL  | 基于某个请求`URL`清除`HTTP`缓存，接受的参数与请求的`URL`需匹配一致，包括`query`部分\nclearAllHTTPCache      | 清除所有的`HTTP`缓存","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fljunb%2Fcookie-fetch","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fljunb%2Fcookie-fetch","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fljunb%2Fcookie-fetch/lists"}