The composite query+supplier cache key.
The result set plus its __cacheMetadata.
Resolves once the write (and any eviction) completes.
await putSupplierQueryCacheEntry("acetone|Loudwolf", { data: [], __cacheMetadata: meta });
export async function putSupplierQueryCacheEntry(
cacheKey: string,
entry: CachedData<unknown>,
): Promise<void> {
try {
const db = await getDB();
const tx = db.transaction(IDB_STORE.SUPPLIER_QUERY_CACHE, 'readwrite');
const store = tx.objectStore(IDB_STORE.SUPPLIER_QUERY_CACHE);
// Evict oldest if at capacity
const count = await store.count();
if (count >= MAX_SUPPLIER_CACHE_ENTRIES) {
const index = store.index('cachedAt');
const cursor = await index.openCursor();
if (cursor) {
logger.debug('Evicting oldest supplier query cache entry', {
key: cursor.value.cacheKey,
age:
Math.round((Date.now() - cursor.value.__cacheMetadata.cachedAt) / (60 * 60 * 1000)) +
' hours',
});
await cursor.delete();
}
}
await store.put({
cacheKey,
data: entry.data,
__cacheMetadata: entry.__cacheMetadata,
});
await tx.done;
} catch (error) {
logger.error('Failed to put supplier query cache entry in IndexedDB', { error });
}
}
Writes a supplier query-cache entry, evicting the least recently cached row first when the store is at
maxSupplierCacheEntriescapacity.