From e5c5a04726e45501fe4aae26fc61fab83366595b Mon Sep 17 00:00:00 2001 From: Skillz Date: Sat, 30 May 2020 17:39:13 -0400 Subject: [PATCH] allow disabling cache --- utils/collection.ts | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/utils/collection.ts b/utils/collection.ts index 98d4cf96f..d83082007 100644 --- a/utils/collection.ts +++ b/utils/collection.ts @@ -1,6 +1,17 @@ import { chooseRandom } from "./utils.ts"; export default class Collection extends Map { + maxSize?: number + + set(key: K, value: V) { + // When this collection is maxSizeed make sure we can add first + if (this.maxSize || this.maxSize === 0) { + if (this.size >= this.maxSize) return this; + } + + return super.set(key, value); + } + array() { return [...this.values()]; }