Skip to content

Commit 894a656

Browse files
author
lidakai
committed
feat:local cache sdk develop
1 parent c6b6681 commit 894a656

File tree

18 files changed

+473
-71
lines changed

18 files changed

+473
-71
lines changed

README.md

Lines changed: 2 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -1,47 +1,3 @@
1-
# Modern.js Package
1+
# 数据缓存 sdk
22

3-
## Setup
4-
5-
Install the dependencies:
6-
7-
```bash
8-
pnpm run install
9-
```
10-
11-
## Get Started
12-
13-
Run and debug the module:
14-
15-
```
16-
pnpm run dev
17-
```
18-
19-
Run test cases:
20-
21-
```
22-
pnpm run test
23-
```
24-
25-
Build the module for production:
26-
27-
```
28-
pnpm run build
29-
```
30-
31-
Enable optional features:
32-
33-
```
34-
pnpm run new
35-
```
36-
37-
Other commands:
38-
39-
```
40-
pnpm run lint # Lint and fix source files
41-
pnpm run change # Add a new changeset
42-
pnpm run bump # Update version and changelog via changeset
43-
pnpm run release # Release the package
44-
45-
```
46-
47-
For more information, see the [Modern.js Module documentation](https://modernjs.dev/module-tools/en).
3+
# ⚠️ 非 json 响应会异常

components/table-list-v2

Lines changed: 0 additions & 1 deletion
This file was deleted.

easy-gui

Lines changed: 0 additions & 1 deletion
This file was deleted.

easyvadmin

Lines changed: 0 additions & 1 deletion
This file was deleted.

easyvadmin-monorepo

Lines changed: 0 additions & 1 deletion
This file was deleted.

k8s-apps

Lines changed: 0 additions & 1 deletion
This file was deleted.

package.json

Lines changed: 17 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
2-
"name": "httpLocalCache",
3-
"version": "0.1.0",
2+
"name": "@lidakai/local-cache",
3+
"version": "0.1.3",
44
"jsnext:source": "./src/index.ts",
55
"types": "./dist/types/index.d.ts",
66
"main": "./dist/lib/index.js",
@@ -33,25 +33,29 @@
3333
"node_modules/",
3434
"dist/"
3535
],
36-
"dependencies": {},
37-
"peerDependencies": {},
36+
"dependencies": {
37+
"@types/lodash-es": "^4.17.8",
38+
"eventemitter3": "^5.0.1",
39+
"idb-keyval": "^6.2.1",
40+
"lodash-es": "^4.17.21"
41+
},
3842
"devDependencies": {
39-
"@modern-js/module-tools": "2.27.0",
43+
"@modern-js-app/eslint-config": "2.27.0",
4044
"@modern-js/eslint-config": "2.27.0",
45+
"@modern-js/module-tools": "2.27.0",
4146
"@modern-js/tsconfig": "2.27.0",
42-
"@modern-js-app/eslint-config": "2.27.0",
43-
"rimraf": "~3.0.2",
44-
"lint-staged": "~13.1.0",
45-
"prettier": "~2.8.1",
46-
"husky": "~8.0.1",
47-
"typescript": "~5.0.4",
4847
"@types/jest": "~29.2.4",
4948
"@types/node": "~16.11.7",
50-
"@types/react": "~18.0.26"
49+
"@types/react": "~18.0.26",
50+
"husky": "~8.0.1",
51+
"lint-staged": "~13.1.0",
52+
"prettier": "~2.8.1",
53+
"rimraf": "~3.0.2",
54+
"typescript": "~5.0.4"
5155
},
5256
"sideEffects": [],
5357
"publishConfig": {
5458
"access": "public",
5559
"registry": "https://registry.npmjs.org/"
5660
}
57-
}
61+
}

pnpm-lock.yaml

Lines changed: 44 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/constants/defaultConfig.ts

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
export const defaultStoreVersion = '1.0.0';
2+
export const defaultDbVersion = '1.0.0';
3+
export const defaultDbName = 'easyv_db';
4+
export const defaultStoreName = 'easyv_store';
5+
6+
export type Method =
7+
| 'GET'
8+
| 'POST'
9+
| 'PUT'
10+
| 'DELETE'
11+
| 'OPTIONS'
12+
| 'HEAD'
13+
| 'PATCH';
14+
15+
export interface DB {
16+
dbName: string;
17+
storeName: string;
18+
dbVersion: string;
19+
storeVersion: string;
20+
}
21+
22+
export interface DeaultConfig {
23+
open: true;
24+
fetchFreeze: boolean;
25+
expiration: {
26+
maxEntries: number;
27+
overrideRetain: boolean;
28+
};
29+
db: DB;
30+
rules:
31+
| {
32+
statuses: [number, number];
33+
method: Method;
34+
filters: RegExp[] | RegExp;
35+
}
36+
| ((x: unknown) => boolean);
37+
}
38+
39+
export const deaultConfig: DeaultConfig = {
40+
open: true,
41+
fetchFreeze: false, // 是否冻结window.fetch 防止被覆盖,默认false
42+
expiration: {
43+
maxEntries: 200, // 最多缓存X条数据
44+
overrideRetain: true, // 超限制后处理策略,true覆盖 false停止工作
45+
},
46+
db: {
47+
dbName: defaultDbName,
48+
dbVersion: defaultDbVersion,
49+
storeName: defaultStoreName,
50+
storeVersion: defaultStoreVersion,
51+
},
52+
rules: {
53+
statuses: [0, 200], // 缓存的状态码
54+
method: 'GET',
55+
filters: [/\/api\//],
56+
},
57+
};

src/constants/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export * from './defaultConfig';

0 commit comments

Comments
 (0)