/**
 * @license MIT
 * author: Cube Dev Team
 * @cube-dev/ui-kit v0.0.0-canary-c015414
 * Released under the MIT license.
 */

/**
 * Create a function that caches the result up to the limit.
 */
export function cacheWrapper(handler, limit = 1000) {
    let cache = {};
    let count = 0;
    return ((firstArg, secondArg) => {
        const key = typeof firstArg === 'string' && secondArg == null
            ? firstArg
            : JSON.stringify([firstArg, secondArg]);
        if (!cache[key]) {
            if (count > limit) {
                cache = {};
                count = 0;
            }
            count++;
            cache[key] =
                secondArg == null ? handler(firstArg) : handler(firstArg, secondArg);
        }
        return cache[key];
    });
}

        