From 2485f092211fa9eaf07ab721bfae314be533ecb5 Mon Sep 17 00:00:00 2001 From: Nicolas Chan Date: Thu, 25 Apr 2024 16:43:00 -0700 Subject: [PATCH] v4.12.2 --- package.json | 2 +- server/cache2.js | 14 +++++++++----- 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/package.json b/package.json index dae0412..bea4bdb 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "bell-countdown", - "version": "4.12.1", + "version": "4.12.2", "description": "Countdown to the next time the bell rings at school.", "main": "index.js", "scripts": { diff --git a/server/cache2.js b/server/cache2.js index 123be6e..250e5d6 100644 --- a/server/cache2.js +++ b/server/cache2.js @@ -7,12 +7,16 @@ class Cache { async get (key, f) { const cached = this.cache[key] if (cached && Date.now() > cached.expires) { - const value = await f(key) - if (value) { - this.set(key, value, this.defaultTtlSeconds) - return value + try { + const value = await f(key) + if (value) { + this.set(key, value, this.defaultTtlSeconds) + return value + } + return cached.value + } catch (e) { + return cached.value } - return cached.value } if (cached) { return cached.value