@simonecoelhosfo/optimizely-mcp-server
Version:
Optimizely MCP Server for AI assistants with integrated CLI tools
55 lines • 2.34 kB
JavaScript
/**
* Debug cache behavior to understand why caching isn't working
*/
import { CacheOrchestrator } from './cache/CacheOrchestrator.js';
import { QueryNormalizer } from './cache/QueryNormalizer.js';
console.log('Debugging Cache Behavior...\n');
async function debugCache() {
const orchestrator = new CacheOrchestrator({ enabled: true });
const normalizer = new QueryNormalizer();
let executionCount = 0;
const mockExecutor = async (query) => {
executionCount++;
console.log(`\nExecutor called (count: ${executionCount})`);
console.log(` Query received:`, JSON.stringify(query, null, 2));
// Simulate query execution
await new Promise(resolve => setTimeout(resolve, 100));
return {
data: [{ id: 1, name: 'test' }],
metadata: {
rowCount: 1,
executionTime: 100,
cacheHit: false
}
};
};
// Test 1: String query
console.log('=== Test 1: String Query ===');
const query1 = 'show all flags';
console.log(`Query: "${query1}"`);
const normalized1 = normalizer.normalize(query1);
console.log(`Normalized:`, normalized1);
const result1a = await orchestrator.executeWithCache(query1, mockExecutor);
console.log(`Result 1a - Cached: ${result1a.cached}, Key: ${result1a.cacheKey}`);
const result1b = await orchestrator.executeWithCache(query1, mockExecutor);
console.log(`Result 1b - Cached: ${result1b.cached}, Key: ${result1b.cacheKey}`);
// Test 2: Object query
console.log('\n=== Test 2: Object Query ===');
const query2 = {
find: 'flags',
select: ['id', 'name'],
where: []
};
console.log(`Query:`, query2);
const result2a = await orchestrator.executeWithCache(query2, mockExecutor);
console.log(`Result 2a - Cached: ${result2a.cached}, Key: ${result2a.cacheKey}`);
const result2b = await orchestrator.executeWithCache(query2, mockExecutor);
console.log(`Result 2b - Cached: ${result2b.cached}, Key: ${result2b.cacheKey}`);
// Test 3: Check cache stats
console.log('\n=== Cache Statistics ===');
const stats = orchestrator.getStats();
console.log('Stats:', stats);
orchestrator.shutdown();
}
debugCache().catch(console.error);
//# sourceMappingURL=test-cache-debug.js.map