"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;
