-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathOnionCache.spec.ts
More file actions
102 lines (77 loc) · 3.38 KB
/
OnionCache.spec.ts
File metadata and controls
102 lines (77 loc) · 3.38 KB
1
2
3
4
5
6
7
8
9
10
11
12
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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
import "mocha";
import * as chai from "chai";
import { OnionCache } from './OnionCache';
import { MemoryCache } from './MemoryCache';
const expect = chai.expect;
/* tslint:disable:only-arrow-functions */
describe('OnionCache', function () {
describe('get', function () {
it('should fetch from first cache', async function () {
const fastCache = new MemoryCache();
const slowCache = new MemoryCache();
const cache = new OnionCache(fastCache, slowCache);
const testKey = 'key';
const testValue = 'value';
await fastCache.set(testKey, testValue);
const result = await cache.get(testKey);
expect(result).to.equal(testValue);
});
it('should fetch from second cache if not in first cache', async function () {
const fastCache = new MemoryCache();
const slowCache = new MemoryCache();
const cache = new OnionCache(fastCache, slowCache);
const testKey = 'key';
const testValue = 'value';
await slowCache.set(testKey, testValue);
const result = await cache.get(testKey);
expect(result).to.equal(testValue);
});
it('should populate first cache with data from second cache', async function () {
const fastCache = new MemoryCache();
const slowCache = new MemoryCache();
const cache = new OnionCache(fastCache, slowCache);
const testKey = 'key';
const testValue = 'value';
await slowCache.set(testKey, testValue);
const result1 = await fastCache.get(testKey);
expect(result1).to.equal(undefined);
const result2 = await cache.get(testKey);
expect(result2).to.equal(testValue);
const result3 = await fastCache.get(testKey);
expect(result3).to.equal(testValue);
});
});
describe('set', function () {
it('should set to all caches', async function () {
const fastCache = new MemoryCache();
const slowCache = new MemoryCache();
const cache = new OnionCache(fastCache, slowCache);
const testKey = 'key';
const testValue = 'value';
await cache.set(testKey, testValue);
const result1 = await fastCache.get(testKey);
expect(result1).to.equal(testValue);
const result2 = await slowCache.get(testKey);
expect(result2).to.equal(testValue);
});
});
describe('del', function () {
it('should delete from all caches', async function () {
const fastCache = new MemoryCache();
const slowCache = new MemoryCache();
const cache = new OnionCache(fastCache, slowCache);
const testKey = 'key';
const testValue = 'value';
await cache.set(testKey, testValue);
const result1 = await fastCache.get(testKey);
expect(result1).to.equal(testValue);
const result2 = await slowCache.get(testKey);
expect(result2).to.equal(testValue);
await cache.del(testKey);
const result3 = await fastCache.get(testKey);
expect(result3).to.equal(undefined);
const result4 = await slowCache.get(testKey);
expect(result4).to.equal(undefined);
});
});
});