From 53ee510a1eda0b59198bc6f74c37b703f8aac842 Mon Sep 17 00:00:00 2001 From: Ben Wilson Date: Thu, 7 Dec 2023 09:53:16 -0500 Subject: [PATCH] fix chart, caching --- src/app.controller.ts | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/src/app.controller.ts b/src/app.controller.ts index 8c6e592..6af196b 100644 --- a/src/app.controller.ts +++ b/src/app.controller.ts @@ -24,14 +24,29 @@ export class AppController { @Get('info') public async info() { + + const CACHE_KEY = 'SITE_INFO'; + const cachedResult = await this.cacheManager.get(CACHE_KEY); + + if (cachedResult != null) { + return cachedResult; + } + + const blockData = await this.blocksService.getFoundBlocks(); const userAgents = await this.clientService.getUserAgents(); - return { + const data = { blockData, userAgents, uptime: this.uptime }; + + //1 min + await this.cacheManager.set(CACHE_KEY, data, 1 * 60 * 1000); + + return data; + } @Get('network')