export const staleMemoize = (fn, stale) => {
    const cache = new Map();
    const revalidate = (key, ...args) => {
        const value = fn(...args);
        cache.set(key, { time: Date.now(), value });
        return value;
    };
    // @ts-ignore
    return (...args) => {
        const key = JSON.stringify(args);
        const cacheItem = cache.get(key);
        if (cacheItem) {
            const { value, time } = cacheItem;
            if (time + stale < Date.now()) {
                revalidate(key, ...args);
            }
            return value;
        }
        return revalidate(key, ...args);
    };
};
//# sourceMappingURL=staleMemoize.js.map