koatty_cacheable 1.5.0 → 1.6.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.rollup.config.js +48 -51
- package/CHANGELOG.md +4 -0
- package/README.md +152 -21
- package/dist/README.md +152 -21
- package/dist/index.d.ts +13 -2
- package/dist/index.js +305 -246
- package/dist/index.mjs +304 -247
- package/dist/package.json +26 -20
- package/package.json +26 -20
- package/target/npmlist.json +0 -1
package/.rollup.config.js
CHANGED
|
@@ -3,61 +3,58 @@
|
|
|
3
3
|
* @Usage:
|
|
4
4
|
* @Author: richen
|
|
5
5
|
* @Date: 2021-12-17 10:20:44
|
|
6
|
-
* @LastEditTime:
|
|
6
|
+
* @LastEditTime: 2024-11-04 22:04:45
|
|
7
7
|
*/
|
|
8
|
+
import commonjs from '@rollup/plugin-commonjs';
|
|
8
9
|
import json from "@rollup/plugin-json";
|
|
10
|
+
import resolve from '@rollup/plugin-node-resolve';
|
|
11
|
+
import { builtinModules } from 'module';
|
|
12
|
+
import del from "rollup-plugin-delete";
|
|
9
13
|
import typescript from 'rollup-plugin-typescript2';
|
|
10
14
|
// import babel from '@rollup/plugin-babel';
|
|
15
|
+
const pkg = require('./package.json');
|
|
11
16
|
|
|
12
17
|
export default [
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
declaration: false,
|
|
56
|
-
declarationMap: false,
|
|
57
|
-
module: "ESNext"
|
|
58
|
-
}
|
|
59
|
-
}
|
|
60
|
-
})
|
|
61
|
-
]
|
|
62
|
-
}
|
|
18
|
+
{
|
|
19
|
+
input: './src/index.ts',
|
|
20
|
+
output: [
|
|
21
|
+
{
|
|
22
|
+
format: 'cjs',
|
|
23
|
+
file: './dist/index.js',
|
|
24
|
+
banner: require('./scripts/copyright'),
|
|
25
|
+
},
|
|
26
|
+
{
|
|
27
|
+
format: 'es',
|
|
28
|
+
file: './dist/index.mjs',
|
|
29
|
+
banner: require('./scripts/copyright'),
|
|
30
|
+
},
|
|
31
|
+
],
|
|
32
|
+
plugins: [
|
|
33
|
+
del({ targets: ["dist/*", "temp/*", "docs/api"] }),
|
|
34
|
+
// babel({
|
|
35
|
+
// babelHelpers: "runtime",
|
|
36
|
+
// configFile: './babel.config.js',
|
|
37
|
+
// exclude: 'node_modules/**',
|
|
38
|
+
// }),
|
|
39
|
+
json(),
|
|
40
|
+
resolve({
|
|
41
|
+
preferBuiltins: true, // 优先选择内置模块
|
|
42
|
+
}),
|
|
43
|
+
commonjs(),
|
|
44
|
+
typescript({
|
|
45
|
+
tsconfigOverride: {
|
|
46
|
+
compilerOptions: {
|
|
47
|
+
declaration: false,
|
|
48
|
+
declarationMap: false,
|
|
49
|
+
module: "ESNext"
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
})
|
|
53
|
+
],
|
|
54
|
+
external: [
|
|
55
|
+
...builtinModules, // 排除 Node.js 内置模块
|
|
56
|
+
...Object.keys(pkg.dependencies || {}), // 排除 package.json 中的外部依赖
|
|
57
|
+
],
|
|
58
|
+
},
|
|
59
|
+
|
|
63
60
|
]
|
package/CHANGELOG.md
CHANGED
|
@@ -2,6 +2,10 @@
|
|
|
2
2
|
|
|
3
3
|
All notable changes to this project will be documented in this file. See [standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines.
|
|
4
4
|
|
|
5
|
+
### [1.6.1](https://github.com/thinkkoa/koatty_cacheable/compare/v1.6.0...v1.6.1) (2025-06-09)
|
|
6
|
+
|
|
7
|
+
## [1.6.0](https://github.com/thinkkoa/koatty_cacheable/compare/v1.5.0...v1.6.0) (2024-11-07)
|
|
8
|
+
|
|
5
9
|
## [1.5.0](https://github.com/thinkkoa/koatty_cacheable/compare/v1.4.3...v1.5.0) (2024-04-01)
|
|
6
10
|
|
|
7
11
|
|
package/README.md
CHANGED
|
@@ -1,19 +1,36 @@
|
|
|
1
1
|
# koatty_cacheable
|
|
2
|
+
|
|
2
3
|
Cacheable for koatty.
|
|
3
4
|
|
|
4
|
-
Koatty框架的 CacheAble,
|
|
5
|
+
Koatty框架的 CacheAble, CacheEvict 缓存装饰器支持库,提供方法级别的缓存功能。
|
|
6
|
+
|
|
7
|
+
## 特性
|
|
8
|
+
|
|
9
|
+
- 🚀 **简单易用**: 通过装饰器轻松添加缓存功能
|
|
10
|
+
- 🔄 **自动缓存**: `@CacheAble` 装饰器自动缓存方法返回值
|
|
11
|
+
- 🗑️ **智能清除**: `@CacheEvict` 装饰器智能清除相关缓存
|
|
12
|
+
- ⚡ **延迟双删**: 支持延迟双删策略,解决缓存一致性问题
|
|
13
|
+
- 🔧 **多后端支持**: 支持 Memory 和 Redis 缓存后端
|
|
14
|
+
- 🎯 **参数化缓存**: 支持基于方法参数的缓存键生成
|
|
15
|
+
- 🛡️ **类型安全**: 完整的 TypeScript 支持
|
|
5
16
|
|
|
17
|
+
## 安装
|
|
6
18
|
|
|
7
|
-
|
|
19
|
+
```bash
|
|
20
|
+
npm install koatty_cacheable
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
## 配置
|
|
8
24
|
|
|
9
|
-
db.ts
|
|
25
|
+
在 koatty 项目的 `db.ts` 配置文件中添加缓存配置:
|
|
10
26
|
|
|
11
|
-
```
|
|
27
|
+
```typescript
|
|
12
28
|
export default {
|
|
13
|
-
...
|
|
29
|
+
// ... 其他配置
|
|
14
30
|
|
|
15
31
|
"CacheStore": {
|
|
16
|
-
type: "memory", // redis
|
|
32
|
+
type: "memory", // 缓存类型: "redis" 或 "memory",默认为 "memory"
|
|
33
|
+
// Redis 配置 (当 type 为 "redis" 时)
|
|
17
34
|
// key_prefix: "koatty",
|
|
18
35
|
// host: '127.0.0.1',
|
|
19
36
|
// port: 6379,
|
|
@@ -26,32 +43,146 @@ export default {
|
|
|
26
43
|
// conn_timeout: 30
|
|
27
44
|
},
|
|
28
45
|
|
|
29
|
-
...
|
|
46
|
+
// ... 其他配置
|
|
30
47
|
};
|
|
31
|
-
|
|
32
48
|
```
|
|
33
49
|
|
|
34
|
-
|
|
50
|
+
## 使用方法
|
|
35
51
|
|
|
36
|
-
|
|
52
|
+
### 基本用法
|
|
53
|
+
|
|
54
|
+
```typescript
|
|
37
55
|
import { CacheAble, CacheEvict, GetCacheStore } from "koatty_cacheable";
|
|
38
56
|
|
|
39
|
-
export class
|
|
57
|
+
export class UserService {
|
|
40
58
|
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
//
|
|
59
|
+
// 自动缓存方法返回值
|
|
60
|
+
@CacheAble("userCache", {
|
|
61
|
+
params: ["id"], // 使用 id 参数作为缓存键的一部分
|
|
62
|
+
timeout: 300 // 缓存过期时间(秒),默认 300 秒
|
|
63
|
+
})
|
|
64
|
+
async getUserById(id: string): Promise<User> {
|
|
65
|
+
// 数据库查询逻辑
|
|
66
|
+
return await this.userRepository.findById(id);
|
|
44
67
|
}
|
|
45
68
|
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
//
|
|
69
|
+
// 自动清除相关缓存
|
|
70
|
+
@CacheEvict("userCache", {
|
|
71
|
+
params: ["id"], // 使用 id 参数定位要清除的缓存
|
|
72
|
+
delayedDoubleDeletion: true // 启用延迟双删策略,默认 true
|
|
73
|
+
})
|
|
74
|
+
async updateUser(id: string, userData: Partial<User>): Promise<User> {
|
|
75
|
+
// 更新用户数据
|
|
76
|
+
const updatedUser = await this.userRepository.update(id, userData);
|
|
77
|
+
return updatedUser;
|
|
49
78
|
}
|
|
50
79
|
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
store.
|
|
80
|
+
// 手动操作缓存
|
|
81
|
+
async customCacheOperation() {
|
|
82
|
+
const store = await GetCacheStore(this.app);
|
|
83
|
+
|
|
84
|
+
// 设置缓存
|
|
85
|
+
await store.set("custom:key", "value", 60);
|
|
86
|
+
|
|
87
|
+
// 获取缓存
|
|
88
|
+
const value = await store.get("custom:key");
|
|
89
|
+
|
|
90
|
+
// 删除缓存
|
|
91
|
+
await store.del("custom:key");
|
|
54
92
|
}
|
|
55
93
|
}
|
|
94
|
+
```
|
|
95
|
+
|
|
96
|
+
### 高级用法
|
|
97
|
+
|
|
98
|
+
```typescript
|
|
99
|
+
export class ProductService {
|
|
100
|
+
|
|
101
|
+
// 无参数缓存
|
|
102
|
+
@CacheAble("productStats")
|
|
103
|
+
async getProductStats(): Promise<ProductStats> {
|
|
104
|
+
return await this.calculateStats();
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
// 多参数缓存
|
|
108
|
+
@CacheAble("productSearch", {
|
|
109
|
+
params: ["category", "keyword"],
|
|
110
|
+
timeout: 600
|
|
111
|
+
})
|
|
112
|
+
async searchProducts(category: string, keyword: string, page: number = 1): Promise<Product[]> {
|
|
113
|
+
return await this.productRepository.search(category, keyword, page);
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
// 立即清除缓存(不使用延迟双删)
|
|
117
|
+
@CacheEvict("productSearch", {
|
|
118
|
+
params: ["category"],
|
|
119
|
+
delayedDoubleDeletion: false
|
|
120
|
+
})
|
|
121
|
+
async updateProductCategory(category: string, updates: any): Promise<void> {
|
|
122
|
+
await this.productRepository.updateCategory(category, updates);
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
```
|
|
126
|
+
|
|
127
|
+
## API 文档
|
|
128
|
+
|
|
129
|
+
### @CacheAble(cacheName, options?)
|
|
130
|
+
|
|
131
|
+
自动缓存装饰器,缓存方法的返回值。
|
|
132
|
+
|
|
133
|
+
**参数:**
|
|
134
|
+
- `cacheName: string` - 缓存名称
|
|
135
|
+
- `options?: CacheAbleOpt` - 缓存选项
|
|
136
|
+
- `params?: string[]` - 用作缓存键的参数名数组
|
|
137
|
+
- `timeout?: number` - 缓存过期时间(秒),默认 300
|
|
138
|
+
|
|
139
|
+
### @CacheEvict(cacheName, options?)
|
|
140
|
+
|
|
141
|
+
自动清除缓存装饰器,在方法执行后清除相关缓存。
|
|
142
|
+
|
|
143
|
+
**参数:**
|
|
144
|
+
- `cacheName: string` - 要清除的缓存名称
|
|
145
|
+
- `options?: CacheEvictOpt` - 清除选项
|
|
146
|
+
- `params?: string[]` - 用于定位缓存的参数名数组
|
|
147
|
+
- `delayedDoubleDeletion?: boolean` - 是否启用延迟双删策略,默认 true
|
|
148
|
+
|
|
149
|
+
### GetCacheStore(app?)
|
|
150
|
+
|
|
151
|
+
获取缓存存储实例。
|
|
152
|
+
|
|
153
|
+
**参数:**
|
|
154
|
+
- `app?: Application` - Koatty 应用实例
|
|
155
|
+
|
|
156
|
+
**返回:** `Promise<CacheStore>`
|
|
157
|
+
|
|
158
|
+
## 缓存键生成规则
|
|
159
|
+
|
|
160
|
+
缓存键按以下格式生成:
|
|
161
|
+
```
|
|
162
|
+
{cacheName}:{paramName1}:{paramValue1}:{paramName2}:{paramValue2}...
|
|
163
|
+
```
|
|
164
|
+
|
|
165
|
+
例如:
|
|
166
|
+
- `@CacheAble("user", {params: ["id"]})` + `getUserById("123")` → `user:id:123`
|
|
167
|
+
- 当缓存键长度超过 128 字符时,会自动使用 murmur hash 进行压缩
|
|
168
|
+
|
|
169
|
+
## 延迟双删策略
|
|
170
|
+
|
|
171
|
+
延迟双删是一种解决缓存一致性问题的策略:
|
|
172
|
+
|
|
173
|
+
1. 立即删除缓存
|
|
174
|
+
2. 执行数据更新操作
|
|
175
|
+
3. 延迟 5 秒后再次删除缓存
|
|
176
|
+
|
|
177
|
+
这样可以避免在并发场景下出现脏数据。
|
|
178
|
+
|
|
179
|
+
## 注意事项
|
|
180
|
+
|
|
181
|
+
1. 装饰器只能用于 `SERVICE` 和 `COMPONENT` 类型的类
|
|
182
|
+
2. 被装饰的方法必须是异步方法(返回 Promise)
|
|
183
|
+
3. 缓存的数据会自动进行 JSON 序列化/反序列化
|
|
184
|
+
4. 如果缓存服务不可用,方法会正常执行,不会抛出错误
|
|
185
|
+
|
|
186
|
+
## 许可证
|
|
56
187
|
|
|
57
|
-
|
|
188
|
+
BSD-3-Clause
|
package/dist/README.md
CHANGED
|
@@ -1,19 +1,36 @@
|
|
|
1
1
|
# koatty_cacheable
|
|
2
|
+
|
|
2
3
|
Cacheable for koatty.
|
|
3
4
|
|
|
4
|
-
Koatty框架的 CacheAble,
|
|
5
|
+
Koatty框架的 CacheAble, CacheEvict 缓存装饰器支持库,提供方法级别的缓存功能。
|
|
6
|
+
|
|
7
|
+
## 特性
|
|
8
|
+
|
|
9
|
+
- 🚀 **简单易用**: 通过装饰器轻松添加缓存功能
|
|
10
|
+
- 🔄 **自动缓存**: `@CacheAble` 装饰器自动缓存方法返回值
|
|
11
|
+
- 🗑️ **智能清除**: `@CacheEvict` 装饰器智能清除相关缓存
|
|
12
|
+
- ⚡ **延迟双删**: 支持延迟双删策略,解决缓存一致性问题
|
|
13
|
+
- 🔧 **多后端支持**: 支持 Memory 和 Redis 缓存后端
|
|
14
|
+
- 🎯 **参数化缓存**: 支持基于方法参数的缓存键生成
|
|
15
|
+
- 🛡️ **类型安全**: 完整的 TypeScript 支持
|
|
5
16
|
|
|
17
|
+
## 安装
|
|
6
18
|
|
|
7
|
-
|
|
19
|
+
```bash
|
|
20
|
+
npm install koatty_cacheable
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
## 配置
|
|
8
24
|
|
|
9
|
-
db.ts
|
|
25
|
+
在 koatty 项目的 `db.ts` 配置文件中添加缓存配置:
|
|
10
26
|
|
|
11
|
-
```
|
|
27
|
+
```typescript
|
|
12
28
|
export default {
|
|
13
|
-
...
|
|
29
|
+
// ... 其他配置
|
|
14
30
|
|
|
15
31
|
"CacheStore": {
|
|
16
|
-
type: "memory", // redis
|
|
32
|
+
type: "memory", // 缓存类型: "redis" 或 "memory",默认为 "memory"
|
|
33
|
+
// Redis 配置 (当 type 为 "redis" 时)
|
|
17
34
|
// key_prefix: "koatty",
|
|
18
35
|
// host: '127.0.0.1',
|
|
19
36
|
// port: 6379,
|
|
@@ -26,32 +43,146 @@ export default {
|
|
|
26
43
|
// conn_timeout: 30
|
|
27
44
|
},
|
|
28
45
|
|
|
29
|
-
...
|
|
46
|
+
// ... 其他配置
|
|
30
47
|
};
|
|
31
|
-
|
|
32
48
|
```
|
|
33
49
|
|
|
34
|
-
|
|
50
|
+
## 使用方法
|
|
35
51
|
|
|
36
|
-
|
|
52
|
+
### 基本用法
|
|
53
|
+
|
|
54
|
+
```typescript
|
|
37
55
|
import { CacheAble, CacheEvict, GetCacheStore } from "koatty_cacheable";
|
|
38
56
|
|
|
39
|
-
export class
|
|
57
|
+
export class UserService {
|
|
40
58
|
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
//
|
|
59
|
+
// 自动缓存方法返回值
|
|
60
|
+
@CacheAble("userCache", {
|
|
61
|
+
params: ["id"], // 使用 id 参数作为缓存键的一部分
|
|
62
|
+
timeout: 300 // 缓存过期时间(秒),默认 300 秒
|
|
63
|
+
})
|
|
64
|
+
async getUserById(id: string): Promise<User> {
|
|
65
|
+
// 数据库查询逻辑
|
|
66
|
+
return await this.userRepository.findById(id);
|
|
44
67
|
}
|
|
45
68
|
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
//
|
|
69
|
+
// 自动清除相关缓存
|
|
70
|
+
@CacheEvict("userCache", {
|
|
71
|
+
params: ["id"], // 使用 id 参数定位要清除的缓存
|
|
72
|
+
delayedDoubleDeletion: true // 启用延迟双删策略,默认 true
|
|
73
|
+
})
|
|
74
|
+
async updateUser(id: string, userData: Partial<User>): Promise<User> {
|
|
75
|
+
// 更新用户数据
|
|
76
|
+
const updatedUser = await this.userRepository.update(id, userData);
|
|
77
|
+
return updatedUser;
|
|
49
78
|
}
|
|
50
79
|
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
store.
|
|
80
|
+
// 手动操作缓存
|
|
81
|
+
async customCacheOperation() {
|
|
82
|
+
const store = await GetCacheStore(this.app);
|
|
83
|
+
|
|
84
|
+
// 设置缓存
|
|
85
|
+
await store.set("custom:key", "value", 60);
|
|
86
|
+
|
|
87
|
+
// 获取缓存
|
|
88
|
+
const value = await store.get("custom:key");
|
|
89
|
+
|
|
90
|
+
// 删除缓存
|
|
91
|
+
await store.del("custom:key");
|
|
54
92
|
}
|
|
55
93
|
}
|
|
94
|
+
```
|
|
95
|
+
|
|
96
|
+
### 高级用法
|
|
97
|
+
|
|
98
|
+
```typescript
|
|
99
|
+
export class ProductService {
|
|
100
|
+
|
|
101
|
+
// 无参数缓存
|
|
102
|
+
@CacheAble("productStats")
|
|
103
|
+
async getProductStats(): Promise<ProductStats> {
|
|
104
|
+
return await this.calculateStats();
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
// 多参数缓存
|
|
108
|
+
@CacheAble("productSearch", {
|
|
109
|
+
params: ["category", "keyword"],
|
|
110
|
+
timeout: 600
|
|
111
|
+
})
|
|
112
|
+
async searchProducts(category: string, keyword: string, page: number = 1): Promise<Product[]> {
|
|
113
|
+
return await this.productRepository.search(category, keyword, page);
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
// 立即清除缓存(不使用延迟双删)
|
|
117
|
+
@CacheEvict("productSearch", {
|
|
118
|
+
params: ["category"],
|
|
119
|
+
delayedDoubleDeletion: false
|
|
120
|
+
})
|
|
121
|
+
async updateProductCategory(category: string, updates: any): Promise<void> {
|
|
122
|
+
await this.productRepository.updateCategory(category, updates);
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
```
|
|
126
|
+
|
|
127
|
+
## API 文档
|
|
128
|
+
|
|
129
|
+
### @CacheAble(cacheName, options?)
|
|
130
|
+
|
|
131
|
+
自动缓存装饰器,缓存方法的返回值。
|
|
132
|
+
|
|
133
|
+
**参数:**
|
|
134
|
+
- `cacheName: string` - 缓存名称
|
|
135
|
+
- `options?: CacheAbleOpt` - 缓存选项
|
|
136
|
+
- `params?: string[]` - 用作缓存键的参数名数组
|
|
137
|
+
- `timeout?: number` - 缓存过期时间(秒),默认 300
|
|
138
|
+
|
|
139
|
+
### @CacheEvict(cacheName, options?)
|
|
140
|
+
|
|
141
|
+
自动清除缓存装饰器,在方法执行后清除相关缓存。
|
|
142
|
+
|
|
143
|
+
**参数:**
|
|
144
|
+
- `cacheName: string` - 要清除的缓存名称
|
|
145
|
+
- `options?: CacheEvictOpt` - 清除选项
|
|
146
|
+
- `params?: string[]` - 用于定位缓存的参数名数组
|
|
147
|
+
- `delayedDoubleDeletion?: boolean` - 是否启用延迟双删策略,默认 true
|
|
148
|
+
|
|
149
|
+
### GetCacheStore(app?)
|
|
150
|
+
|
|
151
|
+
获取缓存存储实例。
|
|
152
|
+
|
|
153
|
+
**参数:**
|
|
154
|
+
- `app?: Application` - Koatty 应用实例
|
|
155
|
+
|
|
156
|
+
**返回:** `Promise<CacheStore>`
|
|
157
|
+
|
|
158
|
+
## 缓存键生成规则
|
|
159
|
+
|
|
160
|
+
缓存键按以下格式生成:
|
|
161
|
+
```
|
|
162
|
+
{cacheName}:{paramName1}:{paramValue1}:{paramName2}:{paramValue2}...
|
|
163
|
+
```
|
|
164
|
+
|
|
165
|
+
例如:
|
|
166
|
+
- `@CacheAble("user", {params: ["id"]})` + `getUserById("123")` → `user:id:123`
|
|
167
|
+
- 当缓存键长度超过 128 字符时,会自动使用 murmur hash 进行压缩
|
|
168
|
+
|
|
169
|
+
## 延迟双删策略
|
|
170
|
+
|
|
171
|
+
延迟双删是一种解决缓存一致性问题的策略:
|
|
172
|
+
|
|
173
|
+
1. 立即删除缓存
|
|
174
|
+
2. 执行数据更新操作
|
|
175
|
+
3. 延迟 5 秒后再次删除缓存
|
|
176
|
+
|
|
177
|
+
这样可以避免在并发场景下出现脏数据。
|
|
178
|
+
|
|
179
|
+
## 注意事项
|
|
180
|
+
|
|
181
|
+
1. 装饰器只能用于 `SERVICE` 和 `COMPONENT` 类型的类
|
|
182
|
+
2. 被装饰的方法必须是异步方法(返回 Promise)
|
|
183
|
+
3. 缓存的数据会自动进行 JSON 序列化/反序列化
|
|
184
|
+
4. 如果缓存服务不可用,方法会正常执行,不会抛出错误
|
|
185
|
+
|
|
186
|
+
## 许可证
|
|
56
187
|
|
|
57
|
-
|
|
188
|
+
BSD-3-Clause
|
package/dist/index.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/*!
|
|
2
2
|
* @Author: richen
|
|
3
|
-
* @Date:
|
|
3
|
+
* @Date: 2025-06-09 13:04:42
|
|
4
4
|
* @License: BSD (3-Clause)
|
|
5
5
|
* @Copyright (c) - <richenlin(at)gmail.com>
|
|
6
6
|
* @HomePage: https://koatty.org/
|
|
@@ -64,6 +64,11 @@ export declare interface CacheEvictOpt {
|
|
|
64
64
|
delayedDoubleDeletion?: boolean;
|
|
65
65
|
}
|
|
66
66
|
|
|
67
|
+
/**
|
|
68
|
+
* Close cache store connection for cleanup (mainly for testing)
|
|
69
|
+
*/
|
|
70
|
+
export declare function CloseCacheStore(): Promise<void>;
|
|
71
|
+
|
|
67
72
|
/**
|
|
68
73
|
* get instances of storeCache
|
|
69
74
|
*
|
|
@@ -71,6 +76,12 @@ export declare interface CacheEvictOpt {
|
|
|
71
76
|
* @param {Application} app
|
|
72
77
|
* @returns {*} {CacheStore}
|
|
73
78
|
*/
|
|
74
|
-
export declare function GetCacheStore(app
|
|
79
|
+
export declare function GetCacheStore(app?: Application): Promise<CacheStore>;
|
|
80
|
+
|
|
81
|
+
/**
|
|
82
|
+
* initiation CacheStore connection and client.
|
|
83
|
+
*
|
|
84
|
+
*/
|
|
85
|
+
export declare function InitCacheStore(): Promise<void>;
|
|
75
86
|
|
|
76
87
|
export { }
|