UNPKG

scrabble-solver

Version:

Scrabble Solver 2 - Free, open-source, cross-platform, multi-language analysis tool for Scrabble, Scrabble Duel, Super Scrabble, Letter League, Crossplay, Literaki, and Kelimelik. Quickly find the top-scoring words using the given board and tiles.

34 lines (33 loc) 1.04 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.MemoryCache = void 0; const constants_1 = require("../constants"); class MemoryCache { constructor() { this.cache = {}; this.cacheTimestamps = {}; } get(locale) { return Promise.resolve(this.cache[locale]); } getLastModifiedTimestamp(locale) { return this.cacheTimestamps[locale]; } has(locale) { return typeof this.cache[locale] !== 'undefined'; } isStale(locale) { const timestamp = this.getLastModifiedTimestamp(locale); if (!this.has(locale) || typeof timestamp === 'undefined') { return undefined; } const timeSinceModification = Math.abs(timestamp - Date.now()); return timeSinceModification > constants_1.CACHE_STALE_THRESHOLD; } set(locale, trie) { this.cacheTimestamps[locale] = Date.now(); this.cache[locale] = trie; return Promise.resolve(); } } exports.MemoryCache = MemoryCache;