@aomex/cache 0.0.8 → 2.0.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/CHANGELOG.md +53 -19
- package/LICENSE +1 -1
- package/dist/index.d.ts +111 -63
- package/dist/index.js +239 -82
- package/dist/index.js.map +1 -1
- package/package.json +10 -9
package/CHANGELOG.md
CHANGED
|
@@ -1,37 +1,71 @@
|
|
|
1
|
-
#
|
|
1
|
+
# Change Log
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
All notable changes to this project will be documented in this file.
|
|
4
|
+
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
|
|
4
5
|
|
|
5
|
-
|
|
6
|
+
## [2.0.1](https://github.com/aomex/aomex/compare/v2.0.0...v2.0.1) (2024-07-26)
|
|
6
7
|
|
|
7
|
-
- [`43e3481`](https://github.com/aomex/aomex/commit/43e3481ff4edab59642b27527beb72e282b1768c) Thanks [@geekact](https://github.com/geekact)! - feat(cache): add method getAndDelete
|
|
8
8
|
|
|
9
|
-
|
|
9
|
+
### Bug Fixes
|
|
10
10
|
|
|
11
|
-
|
|
11
|
+
* 未更新peerDependencies ([0492453](https://github.com/aomex/aomex/commit/0492453d5a748aa6dd2047622a19a86dc7b6036e))
|
|
12
12
|
|
|
13
|
-
### Patch Changes
|
|
14
13
|
|
|
15
|
-
- [`bf2c963`](https://github.com/aomex/aomex/commit/bf2c9639a609402be2ff094ceabe4fd2231214f8) Thanks [@geekact](https://github.com/geekact)! - fix(cache): forget to return while calling addValue
|
|
16
14
|
|
|
17
|
-
- [`e3b1be4`](https://github.com/aomex/aomex/commit/e3b1be4d02793001d441a1f1b1ced060e95b4f8a) Thanks [@geekact](https://github.com/geekact)! - fix(cache): addValue may be incorrect with multiple threads
|
|
18
15
|
|
|
19
|
-
## 0.0.6
|
|
20
16
|
|
|
21
|
-
|
|
17
|
+
# [2.0.0](https://github.com/aomex/aomex/compare/v1.7.0...v2.0.0) (2024-07-26)
|
|
22
18
|
|
|
23
|
-
- [`827b86d`](https://github.com/aomex/aomex/commit/827b86d692786b5708c8602e5985eedabf632981) Thanks [@geekact](https://github.com/geekact)! - feat(cache): change lru as public field
|
|
24
19
|
|
|
25
|
-
|
|
20
|
+
### Features
|
|
26
21
|
|
|
27
|
-
|
|
22
|
+
* **cache:** 新的缓存库 ([cca0b52](https://github.com/aomex/aomex/commit/cca0b52d86029fb1303cd9bd1f362d2dd8b406b6))
|
|
28
23
|
|
|
29
|
-
### Patch Changes
|
|
30
24
|
|
|
31
|
-
|
|
25
|
+
### BREAKING CHANGES
|
|
32
26
|
|
|
33
|
-
|
|
27
|
+
* **cache:** 1. 删除了memory-cache,redis-cache,file-cache
|
|
28
|
+
2. 采用适配器形式创建缓存实例
|
|
34
29
|
|
|
35
|
-
### Patch Changes
|
|
36
30
|
|
|
37
|
-
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
# [1.7.0](https://github.com/aomex/aomex/compare/v1.6.0...v1.7.0) (2024-07-13)
|
|
35
|
+
|
|
36
|
+
**Note:** Version bump only for package @aomex/internal-cache
|
|
37
|
+
|
|
38
|
+
|
|
39
|
+
|
|
40
|
+
|
|
41
|
+
|
|
42
|
+
# [1.6.0](https://github.com/aomex/aomex/compare/v1.5.1...v1.6.0) (2024-07-05)
|
|
43
|
+
|
|
44
|
+
**Note:** Version bump only for package @aomex/internal-cache
|
|
45
|
+
|
|
46
|
+
|
|
47
|
+
|
|
48
|
+
|
|
49
|
+
|
|
50
|
+
## [1.5.1](https://github.com/aomex/aomex/compare/v1.5.0...v1.5.1) (2024-07-04)
|
|
51
|
+
|
|
52
|
+
**Note:** Version bump only for package @aomex/internal-cache
|
|
53
|
+
|
|
54
|
+
|
|
55
|
+
|
|
56
|
+
|
|
57
|
+
|
|
58
|
+
# [1.3.0](https://github.com/aomex/aomex/compare/v1.2.0...v1.3.0) (2024-06-28)
|
|
59
|
+
|
|
60
|
+
**Note:** Version bump only for package @aomex/internal-cache
|
|
61
|
+
|
|
62
|
+
|
|
63
|
+
|
|
64
|
+
|
|
65
|
+
|
|
66
|
+
# 1.1.0 (2024-06-27)
|
|
67
|
+
|
|
68
|
+
|
|
69
|
+
### Features
|
|
70
|
+
|
|
71
|
+
* 初始化 ([3350159](https://github.com/aomex/aomex/commit/3350159454ad230e6d910405f907293b059b1f49))
|
package/LICENSE
CHANGED
package/dist/index.d.ts
CHANGED
|
@@ -1,100 +1,148 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { I18nMessage } from '@aomex/core';
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
|
|
3
|
+
declare module '@aomex/core' {
|
|
4
|
+
namespace I18n {
|
|
5
|
+
interface Definition {
|
|
6
|
+
cache: {
|
|
7
|
+
wrong_type: I18nMessage;
|
|
8
|
+
not_integer: I18nMessage;
|
|
9
|
+
};
|
|
10
|
+
}
|
|
11
|
+
}
|
|
5
12
|
}
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
13
|
+
|
|
14
|
+
declare abstract class Store {
|
|
15
|
+
connect(): Promise<void>;
|
|
16
|
+
gc(): Promise<void>;
|
|
17
|
+
abstract existsKey(key: string): Promise<boolean>;
|
|
18
|
+
abstract getValue(key: string): Promise<string | null>;
|
|
19
|
+
abstract setValue(key: string, value: string, durationMS?: number): Promise<boolean>;
|
|
20
|
+
abstract setNotExistValue(key: string, value: string, durationMS?: number): Promise<boolean>;
|
|
21
|
+
abstract deleteValue(key: string): Promise<boolean>;
|
|
22
|
+
abstract deleteAllValues(): Promise<boolean>;
|
|
23
|
+
abstract increaseValue(key: string): Promise<number>;
|
|
24
|
+
abstract decreaseValue(key: string): Promise<number>;
|
|
25
|
+
abstract expireKey(key: string, durationMS: number): Promise<boolean>;
|
|
26
|
+
abstract ttlKey(key: string): Promise<number>;
|
|
27
|
+
abstract leftPushValue(key: string, ...values: string[]): Promise<boolean>;
|
|
28
|
+
abstract rightPopValue(key: string): Promise<string | null>;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
declare namespace Caching {
|
|
32
|
+
interface Options {
|
|
33
|
+
/**
|
|
34
|
+
* 删除过期缓存防止占用空间,加快读取速度。概率取值范围:`1-100`。默认值:`10`
|
|
35
|
+
*/
|
|
36
|
+
gcProbability?: number;
|
|
37
|
+
}
|
|
38
|
+
type Types = string | number | object | boolean;
|
|
39
|
+
}
|
|
40
|
+
declare class Caching<S extends Store = Store, T extends object = object> {
|
|
41
|
+
protected readonly gcProbability: number;
|
|
42
|
+
readonly store: S;
|
|
43
|
+
constructor(StoreClass: new (config: T) => S, config: T & Caching.Options);
|
|
9
44
|
/**
|
|
10
|
-
*
|
|
45
|
+
* 查看缓存是否存在
|
|
11
46
|
*/
|
|
12
47
|
exists(key: string): Promise<boolean>;
|
|
13
48
|
/**
|
|
14
|
-
* Get value from specific key and return `null` if defaultValue is not provided.
|
|
15
|
-
* ```typescript
|
|
16
|
-
* await cache.get('non-exist'); // null
|
|
17
|
-
* await cache.get('non-exist', 'my-value'); // my-value
|
|
18
|
-
* ```
|
|
19
|
-
*/
|
|
20
|
-
get<T>(key: string, defaultValue: T): Promise<T>;
|
|
21
|
-
get<T extends string | number | object | boolean>(key: string): Promise<T | null>;
|
|
22
|
-
/**
|
|
23
|
-
* Get specific key and immediately delete this key from engine.
|
|
24
|
-
*/
|
|
25
|
-
getAndDelete<T>(key: string, defaultValue: T): Promise<T>;
|
|
26
|
-
getAndDelete<T extends string | number | object | boolean>(key: string): Promise<T | null>;
|
|
27
|
-
/**
|
|
28
|
-
* Get value from key, a set callback will be triggered when the value is `null`.
|
|
29
49
|
*
|
|
50
|
+
* 获取缓存。如果未找到缓存并且未提供默认值,则返回`null`
|
|
30
51
|
* ```typescript
|
|
31
52
|
* await cache.get('key'); // null
|
|
32
|
-
* await cache.
|
|
33
|
-
* await cache.get('key'); // 'value'
|
|
53
|
+
* await cache.get('key', 'my-value'); // my-value
|
|
34
54
|
* ```
|
|
35
55
|
*/
|
|
36
|
-
|
|
37
|
-
|
|
56
|
+
get<T>(key: string, defaultValue: T): Promise<T>;
|
|
57
|
+
get<T extends Caching.Types>(key: string): Promise<T | null>;
|
|
38
58
|
/**
|
|
39
|
-
*
|
|
59
|
+
* 设置缓存。可以指定过期时间(毫秒)
|
|
40
60
|
*
|
|
41
61
|
* ```typescript
|
|
42
62
|
* await cache.set('key', 'value');
|
|
43
63
|
* await cache.set('key', 'value', 3600);
|
|
44
64
|
* ```
|
|
45
65
|
*/
|
|
46
|
-
set(key: string, value:
|
|
66
|
+
set(key: string, value: Caching.Types, durationMs?: number): Promise<boolean>;
|
|
47
67
|
/**
|
|
48
|
-
*
|
|
68
|
+
* 设置缓存。如果缓存已经存在,则设置失败,返回`false`
|
|
49
69
|
*
|
|
50
70
|
* ```typescript
|
|
51
71
|
* await cache.exists('key'); // false
|
|
52
|
-
* await cache.
|
|
72
|
+
* await cache.setNX('key', 'value'); // true
|
|
53
73
|
*
|
|
54
74
|
* await cache.exists('key'); // true
|
|
55
|
-
* await cache.
|
|
75
|
+
* await cache.setNX('key', 'value'); // false
|
|
56
76
|
* ```
|
|
57
77
|
*/
|
|
58
|
-
|
|
78
|
+
setNX(key: string, value: Caching.Types, durationMs?: number): Promise<boolean>;
|
|
79
|
+
/**
|
|
80
|
+
* 将一个或多个值按顺序插入到列表头部。当 key 存在但不是列表类型时,返回一个错误。
|
|
81
|
+
*
|
|
82
|
+
* 假设当前一个列表 foo=[s],执行 `leftPush('foo', a, b, c)` 后列表 foo=[a, b, c, s]
|
|
83
|
+
*/
|
|
84
|
+
leftPush(key: string, ...values: Caching.Types[]): Promise<boolean>;
|
|
85
|
+
/**
|
|
86
|
+
* 移除列表的最后一个元素,返回值为被移除的元素
|
|
87
|
+
*/
|
|
88
|
+
rightPop<T extends Caching.Types>(key: string): Promise<T | null>;
|
|
89
|
+
/**
|
|
90
|
+
* 将key中储存的数字值增一。
|
|
91
|
+
*
|
|
92
|
+
* 如果key不存在,那么key的值会先被初始化为0,然后再执行操作。
|
|
93
|
+
*
|
|
94
|
+
* 如果值包含错误的类型,或字符串类型的值不能表示为数字,那么返回一个错误。
|
|
95
|
+
*/
|
|
96
|
+
increment(key: string): Promise<number>;
|
|
59
97
|
/**
|
|
60
|
-
*
|
|
98
|
+
* 重新设置缓存时间。如果key不存在,则返回`false`
|
|
99
|
+
*/
|
|
100
|
+
expire(key: string, durationMs: number): Promise<boolean>;
|
|
101
|
+
/**
|
|
102
|
+
* 检测缓存的剩余生存时间(Time to live)
|
|
103
|
+
* - 不存在则返回`-2`
|
|
104
|
+
* - 未设置过期时间则返回`-1`
|
|
105
|
+
* - 已设置过期时间则返回剩余时间,单位**毫秒**
|
|
106
|
+
*/
|
|
107
|
+
ttl(key: string): Promise<number>;
|
|
108
|
+
/**
|
|
109
|
+
* 将key中储存的数字值减一。
|
|
110
|
+
*
|
|
111
|
+
* 如果key不存在,那么key的值会先被初始化为0,然后再执行操作。
|
|
112
|
+
*
|
|
113
|
+
* 如果值包含错误的类型,或字符串类型的值不能表示为数字,那么返回一个错误。
|
|
114
|
+
*/
|
|
115
|
+
decrement(key: string): Promise<number>;
|
|
116
|
+
/**
|
|
117
|
+
* 删除指定缓存
|
|
61
118
|
*/
|
|
62
119
|
delete(key: string): Promise<boolean>;
|
|
63
120
|
/**
|
|
64
|
-
*
|
|
121
|
+
* 删除所有缓存。若指定了keyPrefix,则只删除有该前缀的缓存
|
|
65
122
|
*/
|
|
66
123
|
deleteAll(): Promise<boolean>;
|
|
67
124
|
protected buildKey(key: string): string;
|
|
68
|
-
protected
|
|
69
|
-
protected
|
|
70
|
-
protected abstract getValue(key: string): Promise<string | null>;
|
|
71
|
-
protected abstract setValue(key: string, value: string, duration?: number): Promise<boolean>;
|
|
72
|
-
protected abstract deleteValue(key: string): Promise<boolean>;
|
|
73
|
-
protected abstract deleteAllValues(): Promise<boolean>;
|
|
74
|
-
protected parseValue(value: string | null, defaultValue?: string | number | object | boolean): any;
|
|
125
|
+
protected parseValue(value: string | null, defaultValue?: Caching.Types): any;
|
|
126
|
+
protected applyGC(): Promise<void>;
|
|
75
127
|
}
|
|
76
128
|
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
protected
|
|
92
|
-
protected
|
|
93
|
-
|
|
94
|
-
protected deleteValue(key: string): Promise<boolean>;
|
|
95
|
-
protected syncDeleteValue(key: string): boolean;
|
|
96
|
-
protected deleteAllValues(): Promise<boolean>;
|
|
97
|
-
protected gc(): void;
|
|
129
|
+
declare class CacheMemoryStore extends Store {
|
|
130
|
+
private data;
|
|
131
|
+
existsKey(key: string): Promise<boolean>;
|
|
132
|
+
getValue(key: string): Promise<string | null>;
|
|
133
|
+
setValue(key: string, value: string, duration?: number): Promise<boolean>;
|
|
134
|
+
setNotExistValue(key: string, value: string, duration?: number): Promise<boolean>;
|
|
135
|
+
leftPushValue(key: string, ...values: string[]): Promise<boolean>;
|
|
136
|
+
rightPopValue(key: string): Promise<string | null>;
|
|
137
|
+
increaseValue(key: string): Promise<number>;
|
|
138
|
+
decreaseValue(key: string): Promise<number>;
|
|
139
|
+
deleteValue(key: string): Promise<boolean>;
|
|
140
|
+
deleteAllValues(): Promise<boolean>;
|
|
141
|
+
expireKey(key: string, duration: number): Promise<boolean>;
|
|
142
|
+
ttlKey(key: string): Promise<number>;
|
|
143
|
+
protected getValueSync<T extends 'string' | 'array' | 'any'>(key: string, assertType: T): (T extends 'any' ? string | string[] : T extends 'string' ? string : Array<string>) | null;
|
|
144
|
+
protected setValueSync(key: string, value: string | string[], duration?: number): boolean;
|
|
145
|
+
gc(): Promise<void>;
|
|
98
146
|
}
|
|
99
147
|
|
|
100
|
-
export {
|
|
148
|
+
export { CacheMemoryStore, Caching, Store };
|
package/dist/index.js
CHANGED
|
@@ -1,85 +1,164 @@
|
|
|
1
|
-
// src/
|
|
1
|
+
// src/i18n/locales/en-us.ts
|
|
2
|
+
import { i18n } from "@aomex/core";
|
|
3
|
+
i18n.register("en_US", "cache", {
|
|
4
|
+
wrong_type: "wrong kind of value",
|
|
5
|
+
not_integer: "value is not an integer"
|
|
6
|
+
});
|
|
7
|
+
|
|
8
|
+
// src/i18n/locales/zh-cn.ts
|
|
9
|
+
import { i18n as i18n2 } from "@aomex/core";
|
|
10
|
+
i18n2.register("zh_CN", "cache", {
|
|
11
|
+
wrong_type: "\u9519\u8BEF\u7684\u503C\u7C7B\u578B",
|
|
12
|
+
not_integer: "\u503C\u4E0D\u662F\u6574\u6570\u7C7B\u578B"
|
|
13
|
+
});
|
|
14
|
+
|
|
15
|
+
// src/caching.ts
|
|
2
16
|
import { createHash } from "node:crypto";
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
17
|
+
|
|
18
|
+
// src/store.ts
|
|
19
|
+
var Store = class {
|
|
20
|
+
async connect() {
|
|
21
|
+
}
|
|
22
|
+
async gc() {
|
|
23
|
+
}
|
|
24
|
+
};
|
|
25
|
+
|
|
26
|
+
// src/caching.ts
|
|
27
|
+
var Caching = class {
|
|
28
|
+
gcProbability;
|
|
29
|
+
store;
|
|
30
|
+
constructor(StoreClass, config) {
|
|
31
|
+
this.gcProbability = (config.gcProbability ?? 10) / 100;
|
|
32
|
+
this.store = new StoreClass(config);
|
|
33
|
+
this.store.connect();
|
|
7
34
|
}
|
|
8
35
|
/**
|
|
9
|
-
*
|
|
36
|
+
* 查看缓存是否存在
|
|
10
37
|
*/
|
|
11
38
|
async exists(key) {
|
|
12
|
-
|
|
39
|
+
await this.store.connect();
|
|
40
|
+
return this.store.existsKey(this.buildKey(key));
|
|
13
41
|
}
|
|
14
42
|
async get(key, defaultValue) {
|
|
43
|
+
await this.store.connect();
|
|
15
44
|
const hashKey = this.buildKey(key);
|
|
16
|
-
const result = await this.getValue(hashKey);
|
|
45
|
+
const result = await this.store.getValue(hashKey);
|
|
17
46
|
return this.parseValue(result, defaultValue);
|
|
18
47
|
}
|
|
19
|
-
async getAndDelete(key, defaultValue) {
|
|
20
|
-
const result = await this.get(key, defaultValue);
|
|
21
|
-
if (result !== null) {
|
|
22
|
-
await this.delete(key);
|
|
23
|
-
}
|
|
24
|
-
return result;
|
|
25
|
-
}
|
|
26
|
-
async getOrSet(key, orSet, duration) {
|
|
27
|
-
let value = await this.get(key);
|
|
28
|
-
if (value !== null)
|
|
29
|
-
return value;
|
|
30
|
-
await this.set(key, await orSet(), duration);
|
|
31
|
-
return await this.get(key);
|
|
32
|
-
}
|
|
33
48
|
/**
|
|
34
|
-
*
|
|
49
|
+
* 设置缓存。可以指定过期时间(毫秒)
|
|
35
50
|
*
|
|
36
51
|
* ```typescript
|
|
37
52
|
* await cache.set('key', 'value');
|
|
38
53
|
* await cache.set('key', 'value', 3600);
|
|
39
54
|
* ```
|
|
40
55
|
*/
|
|
41
|
-
async set(key, value,
|
|
56
|
+
async set(key, value, durationMs) {
|
|
57
|
+
await this.store.connect();
|
|
58
|
+
await this.applyGC();
|
|
42
59
|
const hashKey = this.buildKey(key);
|
|
43
|
-
return this.setValue(hashKey, JSON.stringify(value),
|
|
60
|
+
return this.store.setValue(hashKey, JSON.stringify(value), durationMs);
|
|
44
61
|
}
|
|
45
62
|
/**
|
|
46
|
-
*
|
|
63
|
+
* 设置缓存。如果缓存已经存在,则设置失败,返回`false`
|
|
47
64
|
*
|
|
48
65
|
* ```typescript
|
|
49
66
|
* await cache.exists('key'); // false
|
|
50
|
-
* await cache.
|
|
67
|
+
* await cache.setNX('key', 'value'); // true
|
|
51
68
|
*
|
|
52
69
|
* await cache.exists('key'); // true
|
|
53
|
-
* await cache.
|
|
70
|
+
* await cache.setNX('key', 'value'); // false
|
|
54
71
|
* ```
|
|
55
72
|
*/
|
|
56
|
-
async
|
|
73
|
+
async setNX(key, value, durationMs) {
|
|
74
|
+
await this.store.connect();
|
|
75
|
+
await this.applyGC();
|
|
76
|
+
const hashKey = this.buildKey(key);
|
|
77
|
+
return this.store.setNotExistValue(hashKey, JSON.stringify(value), durationMs);
|
|
78
|
+
}
|
|
79
|
+
/**
|
|
80
|
+
* 将一个或多个值按顺序插入到列表头部。当 key 存在但不是列表类型时,返回一个错误。
|
|
81
|
+
*
|
|
82
|
+
* 假设当前一个列表 foo=[s],执行 `leftPush('foo', a, b, c)` 后列表 foo=[a, b, c, s]
|
|
83
|
+
*/
|
|
84
|
+
async leftPush(key, ...values) {
|
|
85
|
+
if (!values.length) return false;
|
|
86
|
+
await this.store.connect();
|
|
87
|
+
const hashKey = this.buildKey(key);
|
|
88
|
+
return this.store.leftPushValue(
|
|
89
|
+
hashKey,
|
|
90
|
+
...values.map((value) => JSON.stringify(value))
|
|
91
|
+
);
|
|
92
|
+
}
|
|
93
|
+
/**
|
|
94
|
+
* 移除列表的最后一个元素,返回值为被移除的元素
|
|
95
|
+
*/
|
|
96
|
+
async rightPop(key) {
|
|
97
|
+
await this.store.connect();
|
|
98
|
+
const hashKey = this.buildKey(key);
|
|
99
|
+
const result = await this.store.rightPopValue(hashKey);
|
|
100
|
+
return this.parseValue(result);
|
|
101
|
+
}
|
|
102
|
+
/**
|
|
103
|
+
* 将key中储存的数字值增一。
|
|
104
|
+
*
|
|
105
|
+
* 如果key不存在,那么key的值会先被初始化为0,然后再执行操作。
|
|
106
|
+
*
|
|
107
|
+
* 如果值包含错误的类型,或字符串类型的值不能表示为数字,那么返回一个错误。
|
|
108
|
+
*/
|
|
109
|
+
async increment(key) {
|
|
110
|
+
await this.store.connect();
|
|
57
111
|
const hashKey = this.buildKey(key);
|
|
58
|
-
return this.
|
|
112
|
+
return this.store.increaseValue(hashKey);
|
|
59
113
|
}
|
|
60
114
|
/**
|
|
61
|
-
*
|
|
115
|
+
* 重新设置缓存时间。如果key不存在,则返回`false`
|
|
116
|
+
*/
|
|
117
|
+
async expire(key, durationMs) {
|
|
118
|
+
await this.store.connect();
|
|
119
|
+
const hashKey = this.buildKey(key);
|
|
120
|
+
return this.store.expireKey(hashKey, durationMs);
|
|
121
|
+
}
|
|
122
|
+
/**
|
|
123
|
+
* 检测缓存的剩余生存时间(Time to live)
|
|
124
|
+
* - 不存在则返回`-2`
|
|
125
|
+
* - 未设置过期时间则返回`-1`
|
|
126
|
+
* - 已设置过期时间则返回剩余时间,单位**毫秒**
|
|
127
|
+
*/
|
|
128
|
+
async ttl(key) {
|
|
129
|
+
await this.store.connect();
|
|
130
|
+
const hashKey = this.buildKey(key);
|
|
131
|
+
return this.store.ttlKey(hashKey);
|
|
132
|
+
}
|
|
133
|
+
/**
|
|
134
|
+
* 将key中储存的数字值减一。
|
|
135
|
+
*
|
|
136
|
+
* 如果key不存在,那么key的值会先被初始化为0,然后再执行操作。
|
|
137
|
+
*
|
|
138
|
+
* 如果值包含错误的类型,或字符串类型的值不能表示为数字,那么返回一个错误。
|
|
139
|
+
*/
|
|
140
|
+
async decrement(key) {
|
|
141
|
+
await this.store.connect();
|
|
142
|
+
const hashKey = this.buildKey(key);
|
|
143
|
+
return this.store.decreaseValue(hashKey);
|
|
144
|
+
}
|
|
145
|
+
/**
|
|
146
|
+
* 删除指定缓存
|
|
62
147
|
*/
|
|
63
148
|
async delete(key) {
|
|
149
|
+
await this.store.connect();
|
|
64
150
|
const hashKey = this.buildKey(key);
|
|
65
|
-
return this.deleteValue(hashKey);
|
|
151
|
+
return this.store.deleteValue(hashKey);
|
|
66
152
|
}
|
|
67
153
|
/**
|
|
68
|
-
*
|
|
154
|
+
* 删除所有缓存。若指定了keyPrefix,则只删除有该前缀的缓存
|
|
69
155
|
*/
|
|
70
156
|
async deleteAll() {
|
|
71
|
-
|
|
157
|
+
await this.store.connect();
|
|
158
|
+
return this.store.deleteAllValues();
|
|
72
159
|
}
|
|
73
160
|
buildKey(key) {
|
|
74
|
-
|
|
75
|
-
return this.keyPrefix + hashKey;
|
|
76
|
-
}
|
|
77
|
-
async addValue(key, value, duration) {
|
|
78
|
-
if (await this.existsKey(key))
|
|
79
|
-
return false;
|
|
80
|
-
if (!await this.setValue(key, value, duration))
|
|
81
|
-
return false;
|
|
82
|
-
return await this.getValue(key) === value;
|
|
161
|
+
return key.length < 32 ? key : createHash("md5").update(key).digest("hex");
|
|
83
162
|
}
|
|
84
163
|
parseValue(value, defaultValue) {
|
|
85
164
|
if (value === null) {
|
|
@@ -91,61 +170,139 @@ var Cache = class {
|
|
|
91
170
|
return null;
|
|
92
171
|
}
|
|
93
172
|
}
|
|
173
|
+
async applyGC() {
|
|
174
|
+
if (Math.random() > this.gcProbability) return;
|
|
175
|
+
await this.store.gc();
|
|
176
|
+
}
|
|
94
177
|
};
|
|
95
178
|
|
|
96
|
-
// src/memory-
|
|
97
|
-
import {
|
|
98
|
-
var
|
|
99
|
-
|
|
100
|
-
gcProbability;
|
|
101
|
-
constructor(options = {}) {
|
|
102
|
-
super(options);
|
|
103
|
-
this.gcProbability = (options.gcProbability ?? 10) / 100;
|
|
104
|
-
this.lru = new LRUCache({
|
|
105
|
-
max: options.maxItems || 1e3
|
|
106
|
-
});
|
|
107
|
-
}
|
|
108
|
-
async getAndDelete(key, defaultValue) {
|
|
109
|
-
const hashKey = this.buildKey(key);
|
|
110
|
-
const result = this.syncGetValue(hashKey);
|
|
111
|
-
result !== null && this.syncDeleteValue(hashKey);
|
|
112
|
-
return this.parseValue(result, defaultValue);
|
|
113
|
-
}
|
|
179
|
+
// src/cache-memory-store.ts
|
|
180
|
+
import { i18n as i18n3 } from "@aomex/core";
|
|
181
|
+
var CacheMemoryStore = class extends Store {
|
|
182
|
+
data = /* @__PURE__ */ new Map();
|
|
114
183
|
async existsKey(key) {
|
|
115
|
-
return this.
|
|
184
|
+
return this.getValueSync(key, "any") !== null;
|
|
116
185
|
}
|
|
117
186
|
async getValue(key) {
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
syncGetValue(key) {
|
|
121
|
-
const data = this.lru.get(key);
|
|
122
|
-
return data === void 0 ? null : data;
|
|
187
|
+
const value = this.getValueSync(key, "string");
|
|
188
|
+
return value;
|
|
123
189
|
}
|
|
124
190
|
async setValue(key, value, duration) {
|
|
125
|
-
this.
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
191
|
+
return this.setValueSync(key, value, duration);
|
|
192
|
+
}
|
|
193
|
+
async setNotExistValue(key, value, duration) {
|
|
194
|
+
const currentValue = this.getValueSync(key, "string");
|
|
195
|
+
if (currentValue !== null) return false;
|
|
196
|
+
return this.setValueSync(key, value, duration);
|
|
197
|
+
}
|
|
198
|
+
async leftPushValue(key, ...values) {
|
|
199
|
+
let result = this.getValueSync(key, "array");
|
|
200
|
+
if (result === null) result = [];
|
|
201
|
+
result.push(...values);
|
|
202
|
+
this.setValueSync(key, result);
|
|
129
203
|
return true;
|
|
130
204
|
}
|
|
131
|
-
async
|
|
132
|
-
|
|
205
|
+
async rightPopValue(key) {
|
|
206
|
+
let result = this.getValueSync(key, "array");
|
|
207
|
+
if (result === null || !result.length) return null;
|
|
208
|
+
const popValue = result.pop();
|
|
209
|
+
if (result.length) {
|
|
210
|
+
this.setValueSync(key, result);
|
|
211
|
+
} else {
|
|
212
|
+
this.data.delete(key);
|
|
213
|
+
}
|
|
214
|
+
return popValue;
|
|
133
215
|
}
|
|
134
|
-
|
|
135
|
-
|
|
216
|
+
async increaseValue(key) {
|
|
217
|
+
const result = this.getValueSync(key, "string");
|
|
218
|
+
let value;
|
|
219
|
+
if (result === null) {
|
|
220
|
+
this.data.set(key, { value: "0" });
|
|
221
|
+
value = 0;
|
|
222
|
+
} else {
|
|
223
|
+
value = Number(result);
|
|
224
|
+
}
|
|
225
|
+
if (Number.isNaN(value) || !Number.isInteger(value)) {
|
|
226
|
+
throw new Error("\u7F13\u5B58\u503C\u4E0D\u662F\u6574\u6570\u7C7B\u578B");
|
|
227
|
+
}
|
|
228
|
+
this.setValueSync(key, String(++value));
|
|
229
|
+
return value;
|
|
230
|
+
}
|
|
231
|
+
async decreaseValue(key) {
|
|
232
|
+
const result = this.getValueSync(key, "string");
|
|
233
|
+
let value;
|
|
234
|
+
if (result === null) {
|
|
235
|
+
this.data.set(key, { value: "0" });
|
|
236
|
+
value = 0;
|
|
237
|
+
} else {
|
|
238
|
+
value = Number(result);
|
|
239
|
+
}
|
|
240
|
+
if (Number.isNaN(value) || !Number.isInteger(value)) {
|
|
241
|
+
throw new Error(i18n3.t("cache.not_integer"));
|
|
242
|
+
}
|
|
243
|
+
this.setValueSync(key, String(--value));
|
|
244
|
+
return value;
|
|
245
|
+
}
|
|
246
|
+
async deleteValue(key) {
|
|
247
|
+
this.data.delete(key);
|
|
248
|
+
return true;
|
|
136
249
|
}
|
|
137
250
|
async deleteAllValues() {
|
|
138
|
-
this.
|
|
251
|
+
this.data.clear();
|
|
252
|
+
return true;
|
|
253
|
+
}
|
|
254
|
+
async expireKey(key, duration) {
|
|
255
|
+
const result = this.data.get(key);
|
|
256
|
+
if (!result) return false;
|
|
257
|
+
if (result.expires && result.expires < Date.now()) return false;
|
|
258
|
+
result.expires = Date.now() + duration;
|
|
259
|
+
return true;
|
|
260
|
+
}
|
|
261
|
+
async ttlKey(key) {
|
|
262
|
+
const result = this.data.get(key);
|
|
263
|
+
if (!result) return -2;
|
|
264
|
+
if (!result.expires) return -1;
|
|
265
|
+
if (result.expires < Date.now()) return -2;
|
|
266
|
+
return result.expires - Date.now();
|
|
267
|
+
}
|
|
268
|
+
getValueSync(key, assertType) {
|
|
269
|
+
const result = this.data.get(key);
|
|
270
|
+
if (!result) return null;
|
|
271
|
+
if (result.expires && result.expires < Date.now()) return null;
|
|
272
|
+
const value = result.value;
|
|
273
|
+
let isValid = false;
|
|
274
|
+
switch (assertType) {
|
|
275
|
+
case "string":
|
|
276
|
+
isValid = typeof value === "string";
|
|
277
|
+
break;
|
|
278
|
+
case "array":
|
|
279
|
+
isValid = Array.isArray(value);
|
|
280
|
+
break;
|
|
281
|
+
case "any":
|
|
282
|
+
isValid = true;
|
|
283
|
+
break;
|
|
284
|
+
}
|
|
285
|
+
if (!isValid) {
|
|
286
|
+
throw new Error(i18n3.t("cache.wrong_type"));
|
|
287
|
+
}
|
|
288
|
+
return value;
|
|
289
|
+
}
|
|
290
|
+
setValueSync(key, value, duration) {
|
|
291
|
+
this.data.set(key, { value, expires: duration ? Date.now() + duration : void 0 });
|
|
139
292
|
return true;
|
|
140
293
|
}
|
|
141
|
-
gc() {
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
294
|
+
async gc() {
|
|
295
|
+
const now = Date.now();
|
|
296
|
+
this.data = new Map(
|
|
297
|
+
Array.from(this.data.entries()).filter(
|
|
298
|
+
([_, item]) => !item.expires || item.expires > now
|
|
299
|
+
)
|
|
300
|
+
);
|
|
145
301
|
}
|
|
146
302
|
};
|
|
147
303
|
export {
|
|
148
|
-
|
|
149
|
-
|
|
304
|
+
CacheMemoryStore,
|
|
305
|
+
Caching,
|
|
306
|
+
Store
|
|
150
307
|
};
|
|
151
308
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/cache.ts","../src/memory-cache.ts"],"sourcesContent":["import { createHash } from 'node:crypto';\n\nexport interface CacheOptions {\n keyPrefix?: string;\n}\n\nexport abstract class Cache {\n protected readonly keyPrefix: string;\n\n constructor(config: CacheOptions) {\n this.keyPrefix = config.keyPrefix ?? '';\n }\n\n /**\n * Make sure key is not expired.\n */\n async exists(key: string): Promise<boolean> {\n return this.existsKey(this.buildKey(key));\n }\n\n /**\n * Get value from specific key and return `null` if defaultValue is not provided.\n * ```typescript\n * await cache.get('non-exist'); // null\n * await cache.get('non-exist', 'my-value'); // my-value\n * ```\n */\n async get<T>(key: string, defaultValue: T): Promise<T>;\n async get<T extends string | number | object | boolean>(\n key: string,\n ): Promise<T | null>;\n async get(\n key: string,\n defaultValue?: string | number | object | boolean,\n ): Promise<any> {\n const hashKey = this.buildKey(key);\n const result = await this.getValue(hashKey);\n return this.parseValue(result, defaultValue);\n }\n\n /**\n * Get specific key and immediately delete this key from engine.\n */\n async getAndDelete<T>(key: string, defaultValue: T): Promise<T>;\n async getAndDelete<T extends string | number | object | boolean>(\n key: string,\n ): Promise<T | null>;\n async getAndDelete(\n key: string,\n defaultValue?: string | number | object | boolean,\n ): Promise<any> {\n const result = await this.get(key, defaultValue);\n if (result !== null) {\n await this.delete(key);\n }\n return result;\n }\n\n /**\n * Get value from key, a set callback will be triggered when the value is `null`.\n *\n * ```typescript\n * await cache.get('key'); // null\n * await cache.getOrSet('key', () => 'value'); // 'value'\n * await cache.get('key'); // 'value'\n * ```\n */\n async getOrSet<T extends string | number | object | boolean>(\n key: string,\n orSet: () => T,\n duration?: number,\n ): Promise<T>;\n async getOrSet<T extends string | number | object | boolean>(\n key: string,\n orSet: () => Promise<T>,\n duration?: number,\n ): Promise<T>;\n async getOrSet<T extends string | number | object | boolean>(\n key: string,\n orSet: () => T | Promise<T>,\n duration?: number,\n ): Promise<T> {\n let value: T | null = await this.get(key);\n if (value !== null) return value;\n await this.set(key, await orSet(), duration);\n return (await this.get<T>(key))!;\n }\n\n /**\n * Set value\n *\n * ```typescript\n * await cache.set('key', 'value');\n * await cache.set('key', 'value', 3600);\n * ```\n */\n async set(\n key: string,\n value: string | number | object | boolean,\n duration?: number,\n ): Promise<boolean> {\n const hashKey = this.buildKey(key);\n return this.setValue(hashKey, JSON.stringify(value), duration);\n }\n\n /**\n * Set value if a key doesn't exists\n *\n * ```typescript\n * await cache.exists('key'); // false\n * await cache.add('key', 'value'); // true\n *\n * await cache.exists('key'); // true\n * await cache.add('key', 'value'); // false\n * ```\n */\n async add(key: string, value: any, duration?: number): Promise<boolean> {\n const hashKey = this.buildKey(key);\n return this.addValue(hashKey, JSON.stringify(value), duration);\n }\n\n /**\n * Delete a key\n */\n async delete(key: string): Promise<boolean> {\n const hashKey = this.buildKey(key);\n return this.deleteValue(hashKey);\n }\n\n /**\n * Delete all keys\n */\n async deleteAll(): Promise<boolean> {\n return this.deleteAllValues();\n }\n\n protected buildKey(key: string): string {\n const hashKey =\n key.length <= 32 ? key : createHash('md5').update(key).digest('hex');\n return this.keyPrefix + hashKey;\n }\n\n protected async addValue(\n key: string,\n value: string,\n duration?: number,\n ): Promise<boolean> {\n if (await this.existsKey(key)) return false;\n if (!(await this.setValue(key, value, duration))) return false;\n return (await this.getValue(key)) === value;\n }\n\n protected abstract existsKey(key: string): Promise<boolean>;\n protected abstract getValue(key: string): Promise<string | null>;\n protected abstract setValue(\n key: string,\n value: string,\n duration?: number,\n ): Promise<boolean>;\n protected abstract deleteValue(key: string): Promise<boolean>;\n protected abstract deleteAllValues(): Promise<boolean>;\n\n protected parseValue(\n value: string | null,\n defaultValue?: string | number | object | boolean,\n ) {\n if (value === null) {\n return defaultValue === void 0 ? null : defaultValue;\n }\n\n try {\n return JSON.parse(value);\n } catch {\n return null;\n }\n }\n}\n","import { LRUCache } from 'lru-cache';\nimport { Cache, type CacheOptions } from './cache';\n\nexport interface MemoryCacheOptions extends CacheOptions {\n /**\n * Maximum key length, defaults `1000`\n */\n maxItems?: number;\n gcProbability?: number;\n}\n\nexport class MemoryCache extends Cache {\n public readonly lru: LRUCache<string, string>;\n protected readonly gcProbability: number;\n\n constructor(options: MemoryCacheOptions = {}) {\n super(options);\n this.gcProbability = (options.gcProbability ?? 10) / 100;\n this.lru = new LRUCache<string, string>({\n max: options.maxItems || 1000,\n });\n }\n\n override async getAndDelete<T>(key: string, defaultValue: T): Promise<T>;\n override async getAndDelete<T extends string | number | object | boolean>(\n key: string,\n ): Promise<T | null>;\n override async getAndDelete(\n key: string,\n defaultValue?: string | number | object | boolean,\n ): Promise<any> {\n const hashKey = this.buildKey(key);\n const result = this.syncGetValue(hashKey);\n result !== null && this.syncDeleteValue(hashKey);\n return this.parseValue(result, defaultValue);\n }\n\n protected override async existsKey(key: string): Promise<boolean> {\n return this.lru.has(key);\n }\n\n protected async getValue(key: string): Promise<string | null> {\n return this.syncGetValue(key);\n }\n\n protected syncGetValue(key: string): string | null {\n const data = this.lru.get(key);\n return data === undefined ? null : data;\n }\n\n protected async setValue(\n key: string,\n value: string,\n duration?: number,\n ): Promise<boolean> {\n this.gc();\n this.lru.set(key, value, {\n ttl: duration,\n });\n return true;\n }\n\n protected async deleteValue(key: string): Promise<boolean> {\n return this.syncDeleteValue(key);\n }\n\n protected syncDeleteValue(key: string): boolean {\n return this.lru.delete(key);\n }\n\n protected async deleteAllValues(): Promise<boolean> {\n this.lru.clear();\n return true;\n }\n\n protected gc() {\n if (Math.random() > this.gcProbability) return;\n this.lru.purgeStale();\n }\n}\n"],"mappings":";AAAA,SAAS,kBAAkB;AAMpB,IAAe,QAAf,MAAqB;AAAA,EACP;AAAA,EAEnB,YAAY,QAAsB;AAChC,SAAK,YAAY,OAAO,aAAa;AAAA,EACvC;AAAA;AAAA;AAAA;AAAA,EAKA,MAAM,OAAO,KAA+B;AAC1C,WAAO,KAAK,UAAU,KAAK,SAAS,GAAG,CAAC;AAAA,EAC1C;AAAA,EAaA,MAAM,IACJ,KACA,cACc;AACd,UAAM,UAAU,KAAK,SAAS,GAAG;AACjC,UAAM,SAAS,MAAM,KAAK,SAAS,OAAO;AAC1C,WAAO,KAAK,WAAW,QAAQ,YAAY;AAAA,EAC7C;AAAA,EASA,MAAM,aACJ,KACA,cACc;AACd,UAAM,SAAS,MAAM,KAAK,IAAI,KAAK,YAAY;AAC/C,QAAI,WAAW,MAAM;AACnB,YAAM,KAAK,OAAO,GAAG;AAAA,IACvB;AACA,WAAO;AAAA,EACT;AAAA,EAqBA,MAAM,SACJ,KACA,OACA,UACY;AACZ,QAAI,QAAkB,MAAM,KAAK,IAAI,GAAG;AACxC,QAAI,UAAU;AAAM,aAAO;AAC3B,UAAM,KAAK,IAAI,KAAK,MAAM,MAAM,GAAG,QAAQ;AAC3C,WAAQ,MAAM,KAAK,IAAO,GAAG;AAAA,EAC/B;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAUA,MAAM,IACJ,KACA,OACA,UACkB;AAClB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,SAAK,iBAAiB,QAAQ,iBAAiB,MAAM;AACrD,SAAK,MAAM,IAAI,SAAyB;AAAA,MACtC,KAAK,QAAQ,YAAY;AAAA,IAC3B,CAAC;AAAA,EACH;AAAA,EAMA,MAAe,aACb,KACA,cACc;AACd,UAAM,UAAU,KAAK,SAAS,GAAG;AACjC,UAAM,SAAS,KAAK,aAAa,OAAO;AACxC,eAAW,QAAQ,KAAK,gBAAgB,OAAO;AAC/C,WAAO,KAAK,WAAW,QAAQ,YAAY;AAAA,EAC7C;AAAA,EAEA,MAAyB,UAAU,KAA+B;AAChE,WAAO,KAAK,IAAI,IAAI,GAAG;AAAA,EACzB;AAAA,EAEA,MAAgB,SAAS,KAAqC;AAC5D,WAAO,KAAK,aAAa,GAAG;AAAA,EAC9B;AAAA,EAEU,aAAa,KAA4B;AACjD,UAAM,OAAO,KAAK,IAAI,IAAI,GAAG;AAC7B,WAAO,SAAS,SAAY,OAAO;AAAA,EACrC;AAAA,EAEA,MAAgB,SACd,KACA,OACA,UACkB;AAClB,SAAK,GAAG;AACR,SAAK,IAAI,IAAI,KAAK,OAAO;AAAA,MACvB,KAAK;AAAA,IACP,CAAC;AACD,WAAO;AAAA,EACT;AAAA,EAEA,MAAgB,YAAY,KAA+B;AACzD,WAAO,KAAK,gBAAgB,GAAG;AAAA,EACjC;AAAA,EAEU,gBAAgB,KAAsB;AAC9C,WAAO,KAAK,IAAI,OAAO,GAAG;AAAA,EAC5B;AAAA,EAEA,MAAgB,kBAAoC;AAClD,SAAK,IAAI,MAAM;AACf,WAAO;AAAA,EACT;AAAA,EAEU,KAAK;AACb,QAAI,KAAK,OAAO,IAAI,KAAK;AAAe;AACxC,SAAK,IAAI,WAAW;AAAA,EACtB;AACF;","names":[]}
|
|
1
|
+
{"version":3,"sources":["../src/i18n/locales/en-us.ts","../src/i18n/locales/zh-cn.ts","../src/caching.ts","../src/store.ts","../src/cache-memory-store.ts"],"sourcesContent":["import { i18n } from '@aomex/core';\n\ni18n.register('en_US', 'cache', {\n wrong_type: 'wrong kind of value',\n not_integer: 'value is not an integer',\n});\n","import { i18n } from '@aomex/core';\n\ni18n.register('zh_CN', 'cache', {\n wrong_type: '错误的值类型',\n not_integer: '值不是整数类型',\n});\n","import { createHash } from 'node:crypto';\nimport { Store } from './store';\n\nexport namespace Caching {\n export interface Options {\n /**\n * 删除过期缓存防止占用空间,加快读取速度。概率取值范围:`1-100`。默认值:`10`\n */\n gcProbability?: number;\n }\n\n export type Types = string | number | object | boolean;\n}\n\nexport class Caching<S extends Store = Store, T extends object = object> {\n protected readonly gcProbability: number;\n readonly store: S;\n\n constructor(StoreClass: new (config: T) => S, config: T & Caching.Options) {\n this.gcProbability = (config.gcProbability ?? 10) / 100;\n this.store = new StoreClass(config);\n this.store.connect();\n }\n\n /**\n * 查看缓存是否存在\n */\n async exists(key: string): Promise<boolean> {\n await this.store.connect();\n return this.store.existsKey(this.buildKey(key));\n }\n\n /**\n *\n * 获取缓存。如果未找到缓存并且未提供默认值,则返回`null`\n * ```typescript\n * await cache.get('key'); // null\n * await cache.get('key', 'my-value'); // my-value\n * ```\n */\n async get<T>(key: string, defaultValue: T): Promise<T>;\n async get<T extends Caching.Types>(key: string): Promise<T | null>;\n async get(key: string, defaultValue?: Caching.Types): Promise<any> {\n await this.store.connect();\n const hashKey = this.buildKey(key);\n const result = await this.store.getValue(hashKey);\n return this.parseValue(result, defaultValue);\n }\n\n /**\n * 设置缓存。可以指定过期时间(毫秒)\n *\n * ```typescript\n * await cache.set('key', 'value');\n * await cache.set('key', 'value', 3600);\n * ```\n */\n async set(key: string, value: Caching.Types, durationMs?: number): Promise<boolean> {\n await this.store.connect();\n await this.applyGC();\n const hashKey = this.buildKey(key);\n return this.store.setValue(hashKey, JSON.stringify(value), durationMs);\n }\n\n /**\n * 设置缓存。如果缓存已经存在,则设置失败,返回`false`\n *\n * ```typescript\n * await cache.exists('key'); // false\n * await cache.setNX('key', 'value'); // true\n *\n * await cache.exists('key'); // true\n * await cache.setNX('key', 'value'); // false\n * ```\n */\n async setNX(key: string, value: Caching.Types, durationMs?: number): Promise<boolean> {\n await this.store.connect();\n await this.applyGC();\n const hashKey = this.buildKey(key);\n return this.store.setNotExistValue(hashKey, JSON.stringify(value), durationMs);\n }\n\n /**\n * 将一个或多个值按顺序插入到列表头部。当 key 存在但不是列表类型时,返回一个错误。\n *\n * 假设当前一个列表 foo=[s],执行 `leftPush('foo', a, b, c)` 后列表 foo=[a, b, c, s]\n */\n async leftPush(key: string, ...values: Caching.Types[]): Promise<boolean> {\n if (!values.length) return false;\n await this.store.connect();\n const hashKey = this.buildKey(key);\n return this.store.leftPushValue(\n hashKey,\n ...values.map((value) => JSON.stringify(value)),\n );\n }\n\n /**\n * 移除列表的最后一个元素,返回值为被移除的元素\n */\n async rightPop<T extends Caching.Types>(key: string): Promise<T | null> {\n await this.store.connect();\n const hashKey = this.buildKey(key);\n const result = await this.store.rightPopValue(hashKey);\n return this.parseValue(result);\n }\n\n /**\n * 将key中储存的数字值增一。\n *\n * 如果key不存在,那么key的值会先被初始化为0,然后再执行操作。\n *\n * 如果值包含错误的类型,或字符串类型的值不能表示为数字,那么返回一个错误。\n */\n async increment(key: string): Promise<number> {\n await this.store.connect();\n const hashKey = this.buildKey(key);\n return this.store.increaseValue(hashKey);\n }\n\n /**\n * 重新设置缓存时间。如果key不存在,则返回`false`\n */\n async expire(key: string, durationMs: number): Promise<boolean> {\n await this.store.connect();\n const hashKey = this.buildKey(key);\n return this.store.expireKey(hashKey, durationMs);\n }\n\n /**\n * 检测缓存的剩余生存时间(Time to live)\n * - 不存在则返回`-2`\n * - 未设置过期时间则返回`-1`\n * - 已设置过期时间则返回剩余时间,单位**毫秒**\n */\n async ttl(key: string) {\n await this.store.connect();\n const hashKey = this.buildKey(key);\n return this.store.ttlKey(hashKey);\n }\n\n /**\n * 将key中储存的数字值减一。\n *\n * 如果key不存在,那么key的值会先被初始化为0,然后再执行操作。\n *\n * 如果值包含错误的类型,或字符串类型的值不能表示为数字,那么返回一个错误。\n */\n async decrement(key: string): Promise<number> {\n await this.store.connect();\n const hashKey = this.buildKey(key);\n return this.store.decreaseValue(hashKey);\n }\n\n /**\n * 删除指定缓存\n */\n async delete(key: string): Promise<boolean> {\n await this.store.connect();\n const hashKey = this.buildKey(key);\n return this.store.deleteValue(hashKey);\n }\n\n /**\n * 删除所有缓存。若指定了keyPrefix,则只删除有该前缀的缓存\n */\n async deleteAll(): Promise<boolean> {\n await this.store.connect();\n return this.store.deleteAllValues();\n }\n\n protected buildKey(key: string): string {\n return key.length < 32 ? key : createHash('md5').update(key).digest('hex');\n }\n\n protected parseValue(value: string | null, defaultValue?: Caching.Types) {\n if (value === null) {\n return defaultValue === void 0 ? null : defaultValue;\n }\n\n try {\n return JSON.parse(value);\n } catch {\n return null;\n }\n }\n\n protected async applyGC() {\n if (Math.random() > this.gcProbability) return;\n await this.store.gc();\n }\n}\n","export abstract class Store {\n async connect() {}\n async gc() {}\n\n abstract existsKey(key: string): Promise<boolean>;\n abstract getValue(key: string): Promise<string | null>;\n abstract setValue(key: string, value: string, durationMS?: number): Promise<boolean>;\n abstract setNotExistValue(\n key: string,\n value: string,\n durationMS?: number,\n ): Promise<boolean>;\n abstract deleteValue(key: string): Promise<boolean>;\n abstract deleteAllValues(): Promise<boolean>;\n abstract increaseValue(key: string): Promise<number>;\n abstract decreaseValue(key: string): Promise<number>;\n abstract expireKey(key: string, durationMS: number): Promise<boolean>;\n abstract ttlKey(key: string): Promise<number>;\n abstract leftPushValue(key: string, ...values: string[]): Promise<boolean>;\n abstract rightPopValue(key: string): Promise<string | null>;\n}\n","import { i18n } from '@aomex/core';\nimport { Store } from './store';\n\nexport class CacheMemoryStore extends Store {\n private data = new Map<string, { value: string | string[]; expires?: number }>();\n\n override async existsKey(key: string): Promise<boolean> {\n return this.getValueSync(key, 'any') !== null;\n }\n\n override async getValue(key: string): Promise<string | null> {\n const value = this.getValueSync(key, 'string');\n return value;\n }\n\n override async setValue(\n key: string,\n value: string,\n duration?: number,\n ): Promise<boolean> {\n return this.setValueSync(key, value, duration);\n }\n\n override async setNotExistValue(\n key: string,\n value: string,\n duration?: number,\n ): Promise<boolean> {\n const currentValue = this.getValueSync(key, 'string');\n if (currentValue !== null) return false;\n return this.setValueSync(key, value, duration);\n }\n\n override async leftPushValue(key: string, ...values: string[]): Promise<boolean> {\n let result = this.getValueSync(key, 'array');\n if (result === null) result = [];\n result.push(...values);\n this.setValueSync(key, result);\n return true;\n }\n\n override async rightPopValue(key: string): Promise<string | null> {\n let result = this.getValueSync(key, 'array');\n if (result === null || !result.length) return null;\n const popValue = result.pop()!;\n if (result.length) {\n this.setValueSync(key, result);\n } else {\n this.data.delete(key);\n }\n return popValue;\n }\n\n override async increaseValue(key: string): Promise<number> {\n const result = this.getValueSync(key, 'string');\n let value: number;\n if (result === null) {\n this.data.set(key, { value: '0' });\n value = 0;\n } else {\n value = Number(result);\n }\n\n if (Number.isNaN(value) || !Number.isInteger(value)) {\n throw new Error('缓存值不是整数类型');\n }\n\n this.setValueSync(key, String(++value));\n return value;\n }\n\n override async decreaseValue(key: string): Promise<number> {\n const result = this.getValueSync(key, 'string');\n let value: number;\n if (result === null) {\n this.data.set(key, { value: '0' });\n value = 0;\n } else {\n value = Number(result);\n }\n\n if (Number.isNaN(value) || !Number.isInteger(value)) {\n throw new Error(i18n.t('cache.not_integer'));\n }\n\n this.setValueSync(key, String(--value));\n return value;\n }\n\n override async deleteValue(key: string): Promise<boolean> {\n this.data.delete(key);\n return true;\n }\n\n override async deleteAllValues(): Promise<boolean> {\n this.data.clear();\n return true;\n }\n\n override async expireKey(key: string, duration: number): Promise<boolean> {\n const result = this.data.get(key);\n if (!result) return false;\n if (result.expires && result.expires < Date.now()) return false;\n result.expires = Date.now() + duration;\n return true;\n }\n\n override async ttlKey(key: string): Promise<number> {\n const result = this.data.get(key);\n if (!result) return -2;\n if (!result.expires) return -1;\n if (result.expires < Date.now()) return -2;\n return result.expires - Date.now();\n }\n\n protected getValueSync<T extends 'string' | 'array' | 'any'>(\n key: string,\n assertType: T,\n ):\n | (T extends 'any' ? string | string[] : T extends 'string' ? string : Array<string>)\n | null {\n const result = this.data.get(key);\n if (!result) return null;\n if (result.expires && result.expires < Date.now()) return null;\n const value = result.value;\n\n let isValid = false;\n switch (assertType) {\n case 'string':\n isValid = typeof value === 'string';\n break;\n case 'array':\n isValid = Array.isArray(value);\n break;\n case 'any':\n isValid = true;\n break;\n }\n\n if (!isValid) {\n throw new Error(i18n.t('cache.wrong_type'));\n }\n\n return value as any;\n }\n\n protected setValueSync(\n key: string,\n value: string | string[],\n duration?: number,\n ): boolean {\n this.data.set(key, { value, expires: duration ? Date.now() + duration : undefined });\n return true;\n }\n\n override async gc() {\n const now = Date.now();\n this.data = new Map(\n Array.from(this.data.entries()).filter(\n ([_, item]) => !item.expires || item.expires > now,\n ),\n );\n }\n}\n"],"mappings":";AAAA,SAAS,YAAY;AAErB,KAAK,SAAS,SAAS,SAAS;AAAA,EAC9B,YAAY;AAAA,EACZ,aAAa;AACf,CAAC;;;ACLD,SAAS,QAAAA,aAAY;AAErBA,MAAK,SAAS,SAAS,SAAS;AAAA,EAC9B,YAAY;AAAA,EACZ,aAAa;AACf,CAAC;;;ACLD,SAAS,kBAAkB;;;ACApB,IAAe,QAAf,MAAqB;AAAA,EAC1B,MAAM,UAAU;AAAA,EAAC;AAAA,EACjB,MAAM,KAAK;AAAA,EAAC;AAkBd;;;ADNO,IAAM,UAAN,MAAkE;AAAA,EACpD;AAAA,EACV;AAAA,EAET,YAAY,YAAkC,QAA6B;AACzE,SAAK,iBAAiB,OAAO,iBAAiB,MAAM;AACpD,SAAK,QAAQ,IAAI,WAAW,MAAM;AAClC,SAAK,MAAM,QAAQ;AAAA,EACrB;AAAA;AAAA;AAAA;AAAA,EAKA,MAAM,OAAO,KAA+B;AAC1C,UAAM,KAAK,MAAM,QAAQ;AACzB,WAAO,KAAK,MAAM,UAAU,KAAK,SAAS,GAAG,CAAC;AAAA,EAChD;AAAA,EAYA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@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@aomex/cache",
|
|
3
|
-
"version": "
|
|
4
|
-
"description": "",
|
|
3
|
+
"version": "2.0.1",
|
|
4
|
+
"description": "缓存基础类",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
7
7
|
"exports": {
|
|
@@ -21,17 +21,18 @@
|
|
|
21
21
|
"README.md",
|
|
22
22
|
"CHANGELOG.md"
|
|
23
23
|
],
|
|
24
|
-
"keywords": [],
|
|
25
24
|
"repository": "git@github.com:aomex/aomex.git",
|
|
26
25
|
"homepage": "https://aomex.js.org",
|
|
27
26
|
"license": "MIT",
|
|
28
|
-
"
|
|
29
|
-
"
|
|
27
|
+
"engines": {
|
|
28
|
+
"node": "^20.13.0 || ^22"
|
|
29
|
+
},
|
|
30
|
+
"peerDependencies": {
|
|
31
|
+
"@aomex/core": "^2.0.0"
|
|
30
32
|
},
|
|
31
33
|
"devDependencies": {
|
|
32
|
-
"@aomex/
|
|
34
|
+
"@aomex/core": "^2.0.1",
|
|
35
|
+
"@aomex/internal-tools": "^2.0.1"
|
|
33
36
|
},
|
|
34
|
-
"scripts": {
|
|
35
|
-
"test": "vitest"
|
|
36
|
-
}
|
|
37
|
+
"scripts": {}
|
|
37
38
|
}
|