mm_cachebase 1.5.0 → 1.7.0

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/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "mm_cachebase",
3
- "version": "1.5.0",
4
- "description": "一个轻量级的本地缓存类库,提供与Redis兼容的API接口,支持过期时间设置、哈希表操作、数值操作、字符串操作等功能,以及完整的事件通知系统。",
3
+ "version": "1.7.0",
4
+ "description": "一个轻量级的本地缓存类库,提供与Redis兼容的API接口,支持过期时间设置、哈希表操作、数值操作、字符串操作等功能,以及完整的事件通知系统和多文件持久化功能。",
5
5
  "main": "index.js",
6
6
  "scripts": {
7
7
  "test": "node test.js"
@@ -27,7 +27,10 @@
27
27
  "ttl",
28
28
  "expire",
29
29
  "incr",
30
- "decr"
30
+ "decr",
31
+ "persistence",
32
+ "persist",
33
+ "scope"
31
34
  ],
32
35
  "author": "邱文武",
33
36
  "license": "MIT",
package/simple_test.js ADDED
@@ -0,0 +1,70 @@
1
+ const { CacheBase } = require('./index');
2
+ const fs = require('fs');
3
+ const path = require('path');
4
+
5
+ async function simpleTest() {
6
+ console.log('====== 简单持久化测试 ======');
7
+
8
+ const cacheDir = './test_simple_cache';
9
+ const cacheFile = path.join(cacheDir, 'simple_cache.json');
10
+
11
+ // 清理之前的测试文件
12
+ if (fs.existsSync(cacheFile)) {
13
+ fs.unlinkSync(cacheFile);
14
+ console.log('已清理旧测试文件');
15
+ }
16
+
17
+ // 步骤1: 创建缓存并设置数据
18
+ console.log('\n步骤1: 创建缓存并设置数据');
19
+ const cache = new CacheBase({
20
+ persist: true,
21
+ scope: 'simple',
22
+ dir: cacheDir
23
+ });
24
+
25
+ // 直接设置数据
26
+ console.log('设置数据...');
27
+ cache.data['test_key'] = { value: 'test_value', expire: 0 };
28
+ cache.list = ['test_key'];
29
+ console.log('当前data:', cache.data);
30
+ console.log('当前list:', cache.list);
31
+
32
+ // 步骤2: 手动保存
33
+ console.log('\n步骤2: 手动保存数据');
34
+ await cache.save();
35
+
36
+ // 检查文件是否存在且有内容
37
+ if (fs.existsSync(cacheFile)) {
38
+ const content = fs.readFileSync(cacheFile, 'utf8');
39
+ console.log('保存的文件内容:');
40
+ console.log(content);
41
+ } else {
42
+ console.log('错误: 文件未创建');
43
+ }
44
+
45
+ // 步骤3: 销毁缓存
46
+ console.log('\n步骤3: 销毁缓存');
47
+ await cache.dispose();
48
+
49
+ // 步骤4: 创建新缓存,应该加载数据
50
+ console.log('\n步骤4: 创建新缓存,尝试加载数据');
51
+ const newCache = new CacheBase({
52
+ persist: true,
53
+ scope: 'simple',
54
+ dir: cacheDir
55
+ });
56
+
57
+ // 等待一点时间让_loadData完成
58
+ await new Promise(resolve => setTimeout(resolve, 100));
59
+
60
+ // 检查是否加载了数据
61
+ console.log('加载后的data:', newCache.data);
62
+ console.log('加载后的list:', newCache.list);
63
+ console.log('test_key值:', newCache.data.test_key ? newCache.data.test_key.value : 'undefined');
64
+
65
+ // 清理
66
+ await newCache.dispose();
67
+ console.log('\n测试完成!');
68
+ }
69
+
70
+ simpleTest().catch(console.error);
package/test.js CHANGED
@@ -1,78 +1,481 @@
1
- const CacheBase = require('./index.js');
1
+ const { CacheBase, cachebase_admin } = require('./index.js');
2
2
 
3
- async function test() {
4
- var bl, num, arr = [];
5
- var cache = new CacheBase();
6
- await cache.set("a", "张三", 18);
7
- // await cache.set("ac", "张三", 10);
8
- // await cache.set("b", "李四", 10);
9
- // await cache.set("c", "王五", 10);
10
- // await cache.set("d", "十五", 10);
11
- // bl = await cache.set("age1", 10, 10);
12
- bl = await cache.set("age", 13, 10);
13
- setTimeout(async () => {
14
- console.log(await cache.get("age"));
15
- }, 9000);
16
- setTimeout(async () => {
17
- console.log(await cache.get("age"));
18
- }, 10000);
19
- // bl = await cache.addInt("age", -12);
20
- // bl = await cache.add("age", 15, 5);
21
- // console.log(bl);
22
- // console.log(cache.list);
23
- // console.log("修改" + bl);
24
- console.log(await cache.get("age"));
3
+ class TestRunner {
4
+ constructor() {
5
+ this.totalTests = 0;
6
+ this.passedTests = 0;
7
+ this.results = [];
8
+ }
25
9
 
26
- // bl = await cache.del("age");
27
- // bl = await cache.add("d", "十五", 10);
28
- // console.log("添加" + bl);
10
+ async runTest(name, testFunction) {
11
+ this.totalTests++;
12
+ try {
13
+ await testFunction();
14
+ this.passedTests++;
15
+ this.results.push({ name, passed: true });
16
+ console.log(`✅ ${name}`);
17
+ } catch (error) {
18
+ this.results.push({ name, passed: false, error: error.message });
19
+ console.log(`❌ ${name} - ${error.message}`);
20
+ }
21
+ }
29
22
 
30
- // var num = await cache.addInt("age", 11);
31
- // console.log(num);
23
+ displayResults() {
24
+ console.log('\n========== 测试结果 ==========');
25
+ const passRate = (this.passedTests / this.totalTests * 100).toFixed(2);
26
+ console.log(`通过: ${this.passedTests}/${this.totalTests} (${passRate}%)`);
27
+
28
+ // 显示失败的测试
29
+ const failedTests = this.results.filter(r => !r.passed);
30
+ if (failedTests.length > 0) {
31
+ console.log('\n失败的测试:');
32
+ failedTests.forEach(test => {
33
+ console.log(` - ${test.name}: ${test.error}`);
34
+ });
35
+ }
36
+
37
+ return passRate;
38
+ }
39
+ }
32
40
 
33
- // msg = await cache.setrange("a", 4, "asd");
34
- // console.log(msg);
35
- var str = await cache.addStr("a", "丰");
36
- console.log("追加文本" + str);
37
- // var bl = await cache.has("a");
38
- // console.log("是否存在" + bl);
41
+ async function runAllTests() {
42
+ const runner = new TestRunner();
43
+
44
+ // 测试基础方法
45
+ await testBasicMethods(runner);
46
+
47
+ // 测试哈希表方法
48
+ await testHashMethods(runner);
49
+
50
+ // 测试批量操作
51
+ await testBatchOperations(runner);
52
+
53
+ // 测试过期时间
54
+ await testExpiration(runner);
55
+
56
+ // 测试数值操作
57
+ await testNumericOperations(runner);
58
+
59
+ // 测试字符串操作
60
+ await testStringOperations(runner);
61
+
62
+ // 测试事件触发
63
+ await testEvents(runner);
64
+
65
+ // 测试管理功能
66
+ await testAdminFunctions(runner);
67
+
68
+ // 显示测试结果
69
+ return runner.displayResults();
70
+ }
39
71
 
40
- var num = await cache.add("arr", ['第三', '第四'], 8);
41
- bl = await cache.list_clear("arr", ['第三', '第四', '第w']); // 清空数组,并重新增加成员
42
- console.log("清空数组" + bl);
43
- //
44
- // num = await cache.list_set("arr", ['第一', '第三', '第二'], 8);
45
- num = await cache.list_add("arr", '第s');
46
- console.log("设置数组" + num);
47
- var arr = await cache.list_get("arr", 0);
48
- console.log("查到数组", arr)
72
+ // 测试基础方法
73
+ async function testBasicMethods(runner) {
74
+ console.log('\n========== 测试基础方法 ==========');
75
+ const cache = new CacheBase();
76
+
77
+ await runner.runTest('set和get方法', async () => {
78
+ await cache.set('key1', 'value1');
79
+ const value = await cache.get('key1');
80
+ if (value !== 'value1') {
81
+ throw new Error(`预期值: value1, 实际值: ${value}`);
82
+ }
83
+ });
84
+
85
+ await runner.runTest('del方法', async () => {
86
+ await cache.set('key2', 'value2');
87
+ const deleted = await cache.del('key2');
88
+ if (deleted !== 1) {
89
+ throw new Error(`删除失败,预期: 1, 实际: ${deleted}`);
90
+ }
91
+ const value = await cache.get('key2');
92
+ if (value !== undefined) {
93
+ throw new Error(`键未被删除,值: ${value}`);
94
+ }
95
+ });
96
+
97
+ await runner.runTest('exists/has方法', async () => {
98
+ await cache.set('key3', 'value3');
99
+ const exists = await cache.exists('key3');
100
+ if (exists !== 1) {
101
+ throw new Error(`exists失败,预期: 1, 实际: ${exists}`);
102
+ }
103
+ const has = await cache.has('key3');
104
+ if (!has) {
105
+ throw new Error(`has失败,预期: true, 实际: ${has}`);
106
+ }
107
+ });
108
+
109
+ await runner.runTest('keys方法', async () => {
110
+ await cache.flushdb();
111
+ await cache.set('key4', 'value4');
112
+ await cache.set('key5', 'value5');
113
+ const keys = await cache.keys();
114
+ if (keys.length !== 2 || !keys.includes('key4') || !keys.includes('key5')) {
115
+ throw new Error(`keys失败,预期包含key4和key5, 实际: ${JSON.stringify(keys)}`);
116
+ }
117
+ const filteredKeys = await cache.keys('key4*');
118
+ if (filteredKeys.length !== 1 || filteredKeys[0] !== 'key4') {
119
+ throw new Error(`keys过滤失败,预期: ["key4"], 实际: ${JSON.stringify(filteredKeys)}`);
120
+ }
121
+ });
122
+
123
+ await runner.runTest('dbsize方法', async () => {
124
+ const size = await cache.dbsize();
125
+ if (size !== 2) {
126
+ throw new Error(`dbsize失败,预期: 2, 实际: ${size}`);
127
+ }
128
+ });
129
+
130
+ await runner.runTest('getset方法', async () => {
131
+ const oldValue = await cache.getset('key4', 'newvalue4');
132
+ if (oldValue !== 'value4') {
133
+ throw new Error(`getset失败,预期旧值: value4, 实际: ${oldValue}`);
134
+ }
135
+ const newValue = await cache.get('key4');
136
+ if (newValue !== 'newvalue4') {
137
+ throw new Error(`getset失败,预期新值: newvalue4, 实际: ${newValue}`);
138
+ }
139
+ });
140
+
141
+ await runner.runTest('flushdb/clear方法', async () => {
142
+ let result = await cache.flushdb();
143
+ if (result !== 'OK') {
144
+ throw new Error(`flushdb失败,预期: OK, 实际: ${result}`);
145
+ }
146
+ const size = await cache.dbsize();
147
+ if (size !== 0) {
148
+ throw new Error(`flushdb后大小不为0: ${size}`);
149
+ }
150
+
151
+ // 测试clear方法(兼容)
152
+ await cache.set('key6', 'value6');
153
+ result = await cache.clear();
154
+ if (result !== 'OK') {
155
+ throw new Error(`clear失败,预期: OK, 实际: ${result}`);
156
+ }
157
+ const sizeAfterClear = await cache.dbsize();
158
+ if (sizeAfterClear !== 0) {
159
+ throw new Error(`clear后大小不为0: ${sizeAfterClear}`);
160
+ }
161
+ });
162
+ }
49
163
 
50
- // time = await cache.ttl("arr");
51
- // console.log(time);
52
- // bl = await cache.ttl("arr", -1);
53
- // console.log("设置有效期" + bl);
54
- // time = await cache.ttl("arr");
55
- // console.log(time);
164
+ // 测试哈希表方法
165
+ async function testHashMethods(runner) {
166
+ console.log('\n========== 测试哈希表方法 ==========');
167
+ const cache = new CacheBase();
168
+
169
+ await runner.runTest('hset和hget方法', async () => {
170
+ const result1 = await cache.hset('hash1', 'field1', 'value1');
171
+ if (result1 !== 1) {
172
+ throw new Error(`hset新建失败,预期: 1, 实际: ${result1}`);
173
+ }
174
+
175
+ const result2 = await cache.hset('hash1', 'field1', 'value1_updated');
176
+ if (result2 !== 0) {
177
+ throw new Error(`hset更新失败,预期: 0, 实际: ${result2}`);
178
+ }
179
+
180
+ const value = await cache.hget('hash1', 'field1');
181
+ if (value !== 'value1_updated') {
182
+ throw new Error(`hget失败,预期: value1_updated, 实际: ${value}`);
183
+ }
184
+ });
185
+
186
+ await runner.runTest('hgetall方法', async () => {
187
+ await cache.hset('hash1', 'field2', 'value2');
188
+ const hash = await cache.hgetall('hash1');
189
+ if (JSON.stringify(hash) !== JSON.stringify({ field1: 'value1_updated', field2: 'value2' })) {
190
+ throw new Error(`hgetall失败,预期: {"field1":"value1_updated","field2":"value2"}, 实际: ${JSON.stringify(hash)}`);
191
+ }
192
+ });
193
+
194
+ await runner.runTest('hdel方法', async () => {
195
+ const result = await cache.hdel('hash1', 'field1');
196
+ if (result !== 1) {
197
+ throw new Error(`hdel失败,预期: 1, 实际: ${result}`);
198
+ }
199
+ const value = await cache.hget('hash1', 'field1');
200
+ if (value !== undefined) {
201
+ throw new Error(`hdel后字段未被删除,值: ${value}`);
202
+ }
203
+
204
+ // 删除不存在的字段
205
+ const result2 = await cache.hdel('hash1', 'non_existent');
206
+ if (result2 !== 0) {
207
+ throw new Error(`hdel不存在字段失败,预期: 0, 实际: ${result2}`);
208
+ }
209
+ });
210
+ }
56
211
 
57
- var bl = await cache.list_has("arr", '第一');
58
- console.log("包含", bl);
59
- // await cache.sort("arr", 'asc');
60
- // var ar = await cache.list_get("arr", 2);
61
- // console.log(ar);
212
+ // 测试批量操作
213
+ async function testBatchOperations(runner) {
214
+ console.log('\n========== 测试批量操作 ==========');
215
+ const cache = new CacheBase();
216
+
217
+ await runner.runTest('mset方法', async () => {
218
+ const result = await cache.mset({ key7: 'value7', key8: 'value8' });
219
+ if (result !== 'OK') {
220
+ throw new Error(`mset失败,预期: OK, 实际: ${result}`);
221
+ }
222
+ const value7 = await cache.get('key7');
223
+ const value8 = await cache.get('key8');
224
+ if (value7 !== 'value7' || value8 !== 'value8') {
225
+ throw new Error(`mset后值不匹配: key7=${value7}, key8=${value8}`);
226
+ }
227
+ });
228
+
229
+ await runner.runTest('mget方法', async () => {
230
+ const values = await cache.mget(['key7', 'key8', 'non_existent']);
231
+ if (JSON.stringify(values) !== JSON.stringify(['value7', 'value8', undefined])) {
232
+ throw new Error(`mget失败,预期: ["value7","value8",undefined], 实际: ${JSON.stringify(values)}`);
233
+ }
234
+ });
235
+ }
62
236
 
63
- //console.log("取值" + JSON.stringify(arr));
237
+ // 测试过期时间
238
+ async function testExpiration(runner) {
239
+ console.log('\n========== 测试过期时间 ==========');
240
+ const cache = new CacheBase();
241
+
242
+ await runner.runTest('set带过期时间', async () => {
243
+ await cache.set('expire1', 'value1', 1); // 1秒过期
244
+ let ttl = await cache.ttl('expire1');
245
+ if (ttl <= 0) {
246
+ throw new Error(`ttl初始值错误: ${ttl}`);
247
+ }
248
+
249
+ // 等待过期
250
+ await new Promise(resolve => setTimeout(resolve, 1100));
251
+
252
+ ttl = await cache.ttl('expire1');
253
+ if (ttl !== -2) {
254
+ throw new Error(`过期后ttl错误,预期: -2, 实际: ${ttl}`);
255
+ }
256
+
257
+ const value = await cache.get('expire1');
258
+ if (value !== undefined) {
259
+ throw new Error(`过期后键仍存在: ${value}`);
260
+ }
261
+ });
262
+
263
+ await runner.runTest('expire方法', async () => {
264
+ await cache.set('expire2', 'value2');
265
+ const result = await cache.expire('expire2', 1);
266
+ if (result !== 1) {
267
+ throw new Error(`expire设置失败,预期: 1, 实际: ${result}`);
268
+ }
269
+ let ttl = await cache.ttl('expire2');
270
+ if (ttl <= 0) {
271
+ throw new Error(`expire后ttl错误: ${ttl}`);
272
+ }
273
+ });
274
+
275
+ await runner.runTest('persist方法', async () => {
276
+ await cache.set('expire3', 'value3', 30);
277
+ const result = await cache.persist('expire3');
278
+ if (result !== 1) {
279
+ throw new Error(`persist设置失败,预期: 1, 实际: ${result}`);
280
+ }
281
+ const ttl = await cache.ttl('expire3');
282
+ if (ttl !== -1) {
283
+ throw new Error(`persist后ttl错误,预期: -1, 实际: ${ttl}`);
284
+ }
285
+ });
286
+ }
64
287
 
65
- // await cache.del('a_c');
66
- // ret = await cache.clear(); // 清空缓存
67
- // console.log(ret);
68
- var ret = await cache.getrange("a", 2, 3);
69
- console.log("这是?", ret);
70
- // var arr = await cache.keys("a*");
71
- // console.log(arr);
72
- // ret = await cache.clear('a*'); // 清空缓存
73
- // console.log(ret);
74
- console.log("存储的数据字典", cache.dict);
75
- console.log("存储的数据列表", cache.list);
76
- // cache.dispose() // 销毁资源
288
+ // 测试数值操作
289
+ async function testNumericOperations(runner) {
290
+ console.log('\n========== 测试数值操作 ==========');
291
+ const cache = new CacheBase();
292
+
293
+ await runner.runTest('incr方法', async () => {
294
+ const result1 = await cache.incr('counter');
295
+ if (result1 !== 1) {
296
+ throw new Error(`incr初始值失败,预期: 1, 实际: ${result1}`);
297
+ }
298
+ const result2 = await cache.incr('counter');
299
+ if (result2 !== 2) {
300
+ throw new Error(`incr递增失败,预期: 2, 实际: ${result2}`);
301
+ }
302
+ });
303
+
304
+ await runner.runTest('decr方法', async () => {
305
+ const result = await cache.decr('counter');
306
+ if (result !== 1) {
307
+ throw new Error(`decr递减失败,预期: 1, 实际: ${result}`);
308
+ }
309
+ });
310
+
311
+ await runner.runTest('incrby方法', async () => {
312
+ const result = await cache.incrby('counter', 5);
313
+ if (result !== 6) {
314
+ throw new Error(`incrby增加失败,预期: 6, 实际: ${result}`);
315
+ }
316
+ });
317
+
318
+ await runner.runTest('decrby方法', async () => {
319
+ const result = await cache.decrby('counter', 2);
320
+ if (result !== 4) {
321
+ throw new Error(`decrby减少失败,预期: 4, 实际: ${result}`);
322
+ }
323
+ });
324
+
325
+ await runner.runTest('incrbyfloat方法', async () => {
326
+ const result = await cache.incrbyfloat('counter', 0.5);
327
+ if (result !== 4.5) {
328
+ throw new Error(`incrbyfloat增加失败,预期: 4.5, 实际: ${result}`);
329
+ }
330
+ });
331
+
332
+ await runner.runTest('add方法(兼容)', async () => {
333
+ const result = await cache.add('counter', 10);
334
+ if (result !== 14.5) {
335
+ throw new Error(`add增加失败,预期: 14.5, 实际: ${result}`);
336
+ }
337
+ });
338
+
339
+ await runner.runTest('addFloat方法(兼容)', async () => {
340
+ const result = await cache.addFloat('counter', 0.5);
341
+ if (result !== 15) {
342
+ throw new Error(`addFloat增加失败,预期: 15, 实际: ${result}`);
343
+ }
344
+ });
77
345
  }
78
- test();
346
+
347
+ // 测试字符串操作
348
+ async function testStringOperations(runner) {
349
+ console.log('\n========== 测试字符串操作 ==========');
350
+ const cache = new CacheBase();
351
+
352
+ await runner.runTest('append方法', async () => {
353
+ await cache.set('str', 'hello');
354
+ const result = await cache.append('str', ' world');
355
+ if (result !== 11) {
356
+ throw new Error(`append长度错误,预期: 11, 实际: ${result}`);
357
+ }
358
+ const value = await cache.get('str');
359
+ if (value !== 'hello world') {
360
+ throw new Error(`append值错误,预期: hello world, 实际: ${value}`);
361
+ }
362
+ });
363
+
364
+ await runner.runTest('strlen方法', async () => {
365
+ const result = await cache.strlen('str');
366
+ if (result !== 11) {
367
+ throw new Error(`strlen长度错误,预期: 11, 实际: ${result}`);
368
+ }
369
+
370
+ // 不存在的键
371
+ const result2 = await cache.strlen('non_existent');
372
+ if (result2 !== 0) {
373
+ throw new Error(`strlen不存在键错误,预期: 0, 实际: ${result2}`);
374
+ }
375
+ });
376
+
377
+ await runner.runTest('addStr方法(兼容)', async () => {
378
+ const result = await cache.addStr('str', '!');
379
+ if (result !== 12) {
380
+ throw new Error(`addStr长度错误,预期: 12, 实际: ${result}`);
381
+ }
382
+ const value = await cache.get('str');
383
+ if (value !== 'hello world!') {
384
+ throw new Error(`addStr值错误,预期: hello world!, 实际: ${value}`);
385
+ }
386
+ });
387
+ }
388
+
389
+ // 测试事件触发
390
+ async function testEvents(runner) {
391
+ console.log('\n========== 测试事件触发 ==========');
392
+ const cache = new CacheBase();
393
+
394
+ await runner.runTest('set事件触发', async () => {
395
+ return new Promise(async (resolve, reject) => {
396
+ let beforeTriggered = false;
397
+ let afterTriggered = false;
398
+
399
+ cache.once('set_before', (data) => {
400
+ if (data.key === 'event_key' && data.value === 'event_value') {
401
+ beforeTriggered = true;
402
+ }
403
+ });
404
+
405
+ cache.once('set_after', (data) => {
406
+ if (data.key === 'event_key' && data.value === 'event_value' && data.result === 'OK') {
407
+ afterTriggered = true;
408
+ setTimeout(() => {
409
+ if (beforeTriggered && afterTriggered) {
410
+ resolve();
411
+ } else {
412
+ reject(new Error('set事件未全部触发'));
413
+ }
414
+ }, 10);
415
+ }
416
+ });
417
+
418
+ await cache.set('event_key', 'event_value');
419
+ });
420
+ });
421
+
422
+ // 注意:已移除get事件触发测试,因为get方法不再触发事件以提高性能
423
+
424
+ await runner.runTest('error事件触发', async () => {
425
+ return new Promise(async (resolve, reject) => {
426
+ cache.once('mset_error', (data) => {
427
+ if (data.error && data.error.message.includes('必须是对象')) {
428
+ resolve();
429
+ } else {
430
+ reject(new Error('mset_error事件触发但消息不正确'));
431
+ }
432
+ });
433
+
434
+ try {
435
+ await cache.mset(null);
436
+ reject(new Error('mset应抛出错误但没有'));
437
+ } catch (error) {
438
+ // 预期的错误,等待事件触发
439
+ setTimeout(() => {
440
+ reject(new Error('mset_error事件未触发'));
441
+ }, 100);
442
+ }
443
+ });
444
+ });
445
+ }
446
+
447
+ // 测试管理功能
448
+ async function testAdminFunctions(runner) {
449
+ console.log('\n========== 测试管理功能 ==========');
450
+
451
+ await runner.runTest('cachebase_admin创建实例', async () => {
452
+ const cache1 = cachebase_admin('test_scope');
453
+ const cache2 = cachebase_admin('test_scope');
454
+ if (cache1 !== cache2) {
455
+ throw new Error('cachebase_admin应返回相同实例但没有');
456
+ }
457
+
458
+ const cache3 = cachebase_admin('another_scope');
459
+ if (cache1 === cache3) {
460
+ throw new Error('cachebase_admin应返回不同作用域的不同实例但没有');
461
+ }
462
+ });
463
+
464
+ await runner.runTest('dispose方法', async () => {
465
+ const cache = new CacheBase();
466
+ await cache.set('key_to_dispose', 'value');
467
+ cache.dispose();
468
+
469
+ const size = await cache.dbsize();
470
+ if (size !== 0) {
471
+ throw new Error(`dispose后大小不为0: ${size}`);
472
+ }
473
+ });
474
+ }
475
+
476
+ // 运行所有测试
477
+ runAllTests().then(passRate => {
478
+ console.log(`\n测试完成!通过率: ${passRate}%`);
479
+ }).catch(error => {
480
+ console.error('测试运行失败:', error);
481
+ });
@@ -0,0 +1,5 @@
1
+ {
2
+ "data": {},
3
+ "list": [],
4
+ "timestamp": 1759920414864
5
+ }
@@ -0,0 +1,5 @@
1
+ {
2
+ "data": {},
3
+ "list": [],
4
+ "timestamp": 1759920414866
5
+ }
@@ -0,0 +1,5 @@
1
+ {
2
+ "data": {},
3
+ "list": [],
4
+ "timestamp": 1759920414869
5
+ }
@@ -0,0 +1,5 @@
1
+ {
2
+ "data": {},
3
+ "list": [],
4
+ "timestamp": 1759920431894
5
+ }