-
Notifications
You must be signed in to change notification settings - Fork 14
Expand file tree
/
Copy pathtest-cache.js
More file actions
48 lines (40 loc) · 1.79 KB
/
test-cache.js
File metadata and controls
48 lines (40 loc) · 1.79 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
const axios = require('axios');
// Test the token endpoint caching
async function testTokenCache() {
const baseURL = 'http://localhost:3000';
console.log('Testing Token Cache Implementation...\n');
try {
// First request - should fetch from database/cache miss
console.log('1. First request (cache miss):');
const start1 = Date.now();
const response1 = await axios.get(`${baseURL}/tokens?search=BT`);
const end1 = Date.now();
console.log(` Response time: ${end1 - start1}ms`);
console.log(` Cached: ${response1.data.cached}`);
console.log(` Results: ${JSON.stringify(response1.data.results)}\n`);
// Second request - should use cache
console.log('2. Second request (cache hit):');
const start2 = Date.now();
const response2 = await axios.get(`${baseURL}/tokens?search=BT`);
const end2 = Date.now();
console.log(` Response time: ${end2 - start2}ms`);
console.log(` Cached: ${response2.data.cached}`);
console.log(` Results: ${JSON.stringify(response2.data.results)}\n`);
// Third request with different search - should still use cache
console.log('3. Third request (different search, cache hit):');
const start3 = Date.now();
const response3 = await axios.get(`${baseURL}/tokens?search=ET`);
const end3 = Date.now();
console.log(` Response time: ${end3 - start3}ms`);
console.log(` Cached: ${response3.data.cached}`);
console.log(` Results: ${JSON.stringify(response3.data.results)}\n`);
console.log('Cache test completed successfully!');
} catch (error) {
if (error.code === 'ECONNREFUSED') {
console.log('Server is not running. Please start the server first with: npm run start:dev');
} else {
console.log('Error:', error.message);
}
}
}
testTokenCache();