debug(chart): add cache logging to debug cache misses
This commit is contained in:
@@ -70,11 +70,16 @@ function setCached(key: string, data: SuggestChartsResponse): void {
|
|||||||
export async function suggestCharts(request: SuggestChartsRequest): Promise<SuggestChartsResponse> {
|
export async function suggestCharts(request: SuggestChartsRequest): Promise<SuggestChartsResponse> {
|
||||||
// Check cache first
|
// Check cache first
|
||||||
const cacheKey = getCacheKey(request.content || '', request.selection)
|
const cacheKey = getCacheKey(request.content || '', request.selection)
|
||||||
|
console.log('[suggestCharts] Cache key:', cacheKey, 'contentLen:', request.content?.length, 'selectionLen:', request.selection?.length)
|
||||||
|
|
||||||
const cached = getCached(cacheKey)
|
const cached = getCached(cacheKey)
|
||||||
if (cached) {
|
if (cached) {
|
||||||
|
console.log('[suggestCharts] CACHE HIT - returning cached data')
|
||||||
return cached
|
return cached
|
||||||
}
|
}
|
||||||
|
|
||||||
|
console.log('[suggestCharts] CACHE MISS - calling API')
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const response = await fetch('/api/ai/suggest-charts', {
|
const response = await fetch('/api/ai/suggest-charts', {
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
@@ -104,6 +109,9 @@ export async function suggestCharts(request: SuggestChartsRequest): Promise<Sugg
|
|||||||
// Cache successful responses
|
// Cache successful responses
|
||||||
if (!data.error && !data.quotaExceeded) {
|
if (!data.error && !data.quotaExceeded) {
|
||||||
setCached(cacheKey, data)
|
setCached(cacheKey, data)
|
||||||
|
console.log('[suggestCharts] Cached response for key:', cacheKey, 'cache size now:', cache.size)
|
||||||
|
} else {
|
||||||
|
console.log('[suggestCharts] NOT caching (has error or quota exceeded)')
|
||||||
}
|
}
|
||||||
|
|
||||||
return data
|
return data
|
||||||
|
|||||||
Reference in New Issue
Block a user