From 58c7ce0d00052d0b9193f9039cfb2815fe7023ae Mon Sep 17 00:00:00 2001 From: Chris Duncan Date: Wed, 18 Jun 2025 13:57:30 -0700 Subject: [PATCH] Log cache hits. --- src/lib/index.ts | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/lib/index.ts b/src/lib/index.ts index 12a628f..27f2042 100644 --- a/src/lib/index.ts +++ b/src/lib/index.ts @@ -4,17 +4,22 @@ import { NanoPowValidate } from '#lib/validate' import { NanoPowCpu, NanoPowWasm, NanoPowWebgl, NanoPowWebgpu } from '#lib/generate' import { WorkErrorResponse, WorkGenerateResponse, WorkValidateResponse } from '#types' -import { bigintFrom, Cache, Queue } from '#utils' +import { bigintFrom, Cache, Logger, Queue } from '#utils' import { NanoPowConfig } from '#lib/config' +const logger = new Logger() const q = new Queue() export async function work_generate (hash: unknown, options: unknown): Promise { return q.add(async (): Promise => { try { const { api, debug, difficulty, effort } = await NanoPowConfig(options) + LOG: logger.isEnabled = debug const cached = Cache.search(hash, difficulty) - if (cached) return cached + if (cached) { + LOG: logger.log('found work in cache') + return cached + } switch (api) { case 'webgpu': { return Cache.store(await NanoPowWebgpu(bigintFrom(hash, 'hex'), difficulty, effort, debug)) -- 2.47.3