All Downloads are FREE. Search and download functionalities are using the official Maven repository.

package.dist.src.batchutils.batch-functions.js Maven / Gradle / Ivy

The newest version!
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.batchDelete = exports.batchSet = exports.batchGet = exports.defaultTtlSeconds = exports.defaultMaxConcurrentRequests = void 0;
const batch_props_1 = require("./batch-props");
Object.defineProperty(exports, "defaultMaxConcurrentRequests", { enumerable: true, get: function () { return batch_props_1.defaultMaxConcurrentRequests; } });
Object.defineProperty(exports, "defaultTtlSeconds", { enumerable: true, get: function () { return batch_props_1.defaultTtlSeconds; } });
const utils_1 = require("@gomomento/sdk-core/dist/src/internal/utils");
// Note: all promises in batch request workers have a client-side timeout deadline
// because grpc request timeouts are baked into the cache client. The timeout can be
// overridden using the `withClientTimeoutMillis` function.
async function batchGet(cacheClient, cacheName, keys, options) {
    const maxConcurrentGets = (options === null || options === void 0 ? void 0 : options.maxConcurrentRequests)
        ? options.maxConcurrentRequests
        : Math.min(batch_props_1.defaultMaxConcurrentRequests, keys.length);
    const batchGetResults = (0, utils_1.range)(maxConcurrentGets).map((workerId) => getWorker(workerId, cacheClient, cacheName, keys));
    const awaitAll = await Promise.all(batchGetResults);
    const batchGetResponse = {};
    awaitAll.forEach(responses => {
        Object.assign(batchGetResponse, responses);
    });
    return batchGetResponse;
}
exports.batchGet = batchGet;
async function getWorker(workerId, cacheClient, cacheName, keys) {
    const responses = {};
    while (keys.length) {
        const cacheKey = keys.pop();
        if (cacheKey !== undefined) {
            responses[String(cacheKey)] = await cacheClient.get(cacheName, cacheKey);
        }
    }
    return Promise.resolve(responses);
}
async function batchSet(cacheClient, cacheName, items, options) {
    const maxConcurrentSets = (options === null || options === void 0 ? void 0 : options.maxConcurrentRequests)
        ? options.maxConcurrentRequests
        : Math.min(batch_props_1.defaultMaxConcurrentRequests, items.length);
    const batchSetResults = (0, utils_1.range)(maxConcurrentSets).map((workerId) => setWorker(workerId, cacheClient, cacheName, items));
    const awaitAll = await Promise.all(batchSetResults);
    const batchSetResponse = {};
    awaitAll.forEach(responses => {
        Object.assign(batchSetResponse, responses);
    });
    return batchSetResponse;
}
exports.batchSet = batchSet;
async function setWorker(workerId, cacheClient, cacheName, items) {
    const responses = {};
    while (items.length) {
        const item = items.pop();
        if (item !== undefined) {
            responses[String(item.key)] = await cacheClient.set(cacheName, item.key, item.value, { ttl: item.ttl ? item.ttl : batch_props_1.defaultTtlSeconds });
        }
    }
    return Promise.resolve(responses);
}
async function batchDelete(cacheClient, cacheName, keys, options) {
    const maxConcurrentDeletes = (options === null || options === void 0 ? void 0 : options.maxConcurrentRequests)
        ? options.maxConcurrentRequests
        : Math.min(batch_props_1.defaultMaxConcurrentRequests, keys.length);
    const batchDeleteResults = (0, utils_1.range)(maxConcurrentDeletes).map((workerId) => deleteWorker(workerId, cacheClient, cacheName, keys));
    const awaitAll = await Promise.all(batchDeleteResults);
    const batchDeleteResponse = {};
    awaitAll.forEach(responses => {
        Object.assign(batchDeleteResponse, responses);
    });
    return batchDeleteResponse;
}
exports.batchDelete = batchDelete;
async function deleteWorker(workerId, cacheClient, cacheName, keys) {
    const responses = {};
    while (keys.length) {
        const cacheKey = keys.pop();
        if (cacheKey !== undefined) {
            responses[String(cacheKey)] = await cacheClient.delete(cacheName, cacheKey);
        }
    }
    return Promise.resolve(responses);
}
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiYmF0Y2gtZnVuY3Rpb25zLmpzIiwic291cmNlUm9vdCI6IiIsInNvdXJjZXMiOlsiLi4vLi4vLi4vc3JjL2JhdGNodXRpbHMvYmF0Y2gtZnVuY3Rpb25zLnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiI7OztBQU1BLCtDQVV1QjtBQVdyQiw2R0FiQSwwQ0FBNEIsT0FhQTtBQUM1QixrR0FiQSwrQkFBaUIsT0FhQTtBQVhuQix1RUFBa0U7QUFjbEUsa0ZBQWtGO0FBQ2xGLG9GQUFvRjtBQUNwRiwyREFBM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