-
Notifications
You must be signed in to change notification settings - Fork 1
/
test.js
52 lines (41 loc) · 1.18 KB
/
test.js
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
const TEST_URL = process.env.TEST_URL || 'https://google.com';
const CacheOrReq = require('./CacheOrReq');
let cacheOrReq = new CacheOrReq(1000);
cacheOrReq.get({
url: TEST_URL,
method: 'GET'
}).then((data) => {
console.log('data 1 (direct fetch)', data);
cacheOrReq.get({
url: TEST_URL,
method: 'GET'
}).then((data) => {
console.log('data 2 (cached fetch)', data);
});
setTimeout(() => {
cacheOrReq.get({
url: TEST_URL,
method: 'GET'
}).then((data) => {
console.log('data 3 (same cached fetch)', data);
});
setTimeout(() => {
cacheOrReq.get({
url: TEST_URL,
method: 'GET'
}).then((data) => {
console.log('data 4 (renewed cache fetch', data);
});
}, 1000);
}, 3000);
}).catch((error) => {
console.log('data 1 error (direct fetch)', error);
cacheOrReq.get({
url: TEST_URL,
method: 'GET'
}).then((data) => {
console.log('data 2 (cached fetch)', data);
}).catch((error) => {
console.log('data 2 error (cached fetch)', error);
});
});