summaryrefslogtreecommitdiffhomepage
path: root/src/lib/cache/imageCache.ts
diff options
context:
space:
mode:
Diffstat (limited to 'src/lib/cache/imageCache.ts')
-rw-r--r--src/lib/cache/imageCache.ts27
1 files changed, 24 insertions, 3 deletions
diff --git a/src/lib/cache/imageCache.ts b/src/lib/cache/imageCache.ts
index 2326974..5ff7393 100644
--- a/src/lib/cache/imageCache.ts
+++ b/src/lib/cache/imageCache.ts
@@ -109,6 +109,10 @@ async function idbGet(key: CacheKey): Promise<StoredRecord | undefined> {
});
}
+/** Last write error (if any) — exposed via getStats() for diagnostics. */
+let lastWriteError: string | undefined;
+let writeErrorCount = 0;
+
/** Write a record to IndexedDB (best-effort). */
async function idbPut(record: StoredRecord): Promise<void> {
const db = await openDb();
@@ -119,9 +123,22 @@ async function idbPut(record: StoredRecord): Promise<void> {
const tx = db.transaction(STORE_NAME, 'readwrite');
const store = tx.objectStore(STORE_NAME);
store.put(record);
- tx.oncomplete = () => resolve();
- tx.onerror = () => resolve();
- } catch {
+ tx.oncomplete = () => {
+ lastWriteError = undefined;
+ resolve();
+ };
+ tx.onerror = () => {
+ const msg = tx.error?.message ?? 'unknown write error';
+ lastWriteError = msg;
+ writeErrorCount++;
+ console.warn(`[imageCache] IDB write failed: ${msg}`);
+ resolve();
+ };
+ } catch (e) {
+ const msg = e instanceof Error ? e.message : String(e);
+ lastWriteError = msg;
+ writeErrorCount++;
+ console.warn(`[imageCache] IDB write exception: ${msg}`);
resolve();
}
});
@@ -280,6 +297,8 @@ export const imageCache = {
idbEntries: number;
idbBytes: number;
idbError: string | undefined;
+ idbLastWriteError: string | undefined;
+ idbWriteErrorCount: number;
}> {
let fullCount = 0;
let thumbCount = 0;
@@ -332,6 +351,8 @@ export const imageCache = {
idbEntries,
idbBytes,
idbError,
+ idbLastWriteError: lastWriteError,
+ idbWriteErrorCount: writeErrorCount,
};
},