package.dist.src.cache-client.js Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of sdk Show documentation
Show all versions of sdk Show documentation
Client SDK for Momento services
The newest version!
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.SimpleCacheClient = exports.CacheClient = void 0;
const cache_control_client_1 = require("./internal/cache-control-client");
const cache_data_client_1 = require("./internal/cache-data-client");
const _1 = require(".");
const utils_1 = require("@gomomento/sdk-core/dist/src/internal/utils");
const AbstractCacheClient_1 = require("@gomomento/sdk-core/dist/src/internal/clients/cache/AbstractCacheClient");
const sdk_core_1 = require("@gomomento/sdk-core");
const EAGER_CONNECTION_DEFAULT_TIMEOUT_SECONDS = 30;
/**
* Momento Cache Client.
*
* Features include:
* - Get, set, and delete data
* - Create, delete, and list caches
* - Create, revoke, and list signing keys
*/
class CacheClient extends AbstractCacheClient_1.AbstractCacheClient {
/**
* Creates an instance of CacheClient.
* @param {CacheClientProps} props configuration and credentials for creating a CacheClient.
*/
constructor(props) {
var _a, _b;
(0, utils_1.validateTtlSeconds)(props.defaultTtlSeconds);
const configuration = (_a = props.configuration) !== null && _a !== void 0 ? _a : getDefaultCacheClientConfiguration();
const credentialProvider = (_b = props.credentialProvider) !== null && _b !== void 0 ? _b : (0, sdk_core_1.getDefaultCredentialProvider)();
const allProps = {
...props,
configuration: configuration,
credentialProvider: credentialProvider,
};
let semaphore = undefined;
const numConcurrentRequests = configuration
.getTransportStrategy()
.getGrpcConfig()
.getMaxConcurrentRequests();
if (numConcurrentRequests !== null && numConcurrentRequests !== undefined) {
(0, utils_1.validateMaxConcurrentRequests)(numConcurrentRequests);
semaphore = new utils_1.Semaphore(numConcurrentRequests);
}
const controlClient = new cache_control_client_1.CacheControlClient({
configuration: configuration,
credentialProvider: credentialProvider,
});
const numClients = configuration
.getTransportStrategy()
.getGrpcConfig()
.getNumClients();
const dataClients = (0, utils_1.range)(numClients).map((_, id) => new cache_data_client_1.CacheDataClient(allProps, String(id), semaphore));
super(controlClient, dataClients);
this.dataRequestConcurrencySemaphore = undefined;
this._configuration = configuration;
this.notYetAbstractedControlClient = controlClient;
this.dataRequestConcurrencySemaphore = semaphore;
this.logger = configuration.getLoggerFactory().getLogger(this);
this.logger.debug('Creating Momento CacheClient');
// Initialize middlewares that have init methods. These currently start
// background tasks for logging that will execute until they are explicitly
// stopped. This is usually handled by the client's close method, but if
// there is ever a chance that this client constructor may fail after these
// methods are called, it is up to you to catch the exception and call close
// on each of these manually.
this._configuration.getMiddlewares().forEach(m => {
if (m.init) {
m.init();
}
});
}
close() {
if (this.dataRequestConcurrencySemaphore !== undefined) {
this.dataRequestConcurrencySemaphore.purge();
}
this.controlClient.close();
this.dataClients.map(dc => dc.close());
this._configuration.getMiddlewares().forEach(m => {
if (m.close) {
m.close();
}
});
}
/**
* Creates a new instance of CacheClient. If eagerConnectTimeout is present in the given props, the client will
* eagerly create its connection to Momento. It will wait until the connection is established, or until the timout
* runs out. It the timeout runs out, the client will be valid to use, but it may still be connecting in the background.
* @param {EagerCacheClientProps} props configuration and credentials for creating a CacheClient.
*/
static async create(props) {
const client = new CacheClient(props);
try {
const timeout = props.eagerConnectTimeout !== undefined
? props.eagerConnectTimeout
: EAGER_CONNECTION_DEFAULT_TIMEOUT_SECONDS;
// eslint-disable-next-line @typescript-eslint/no-unsafe-call
(0, utils_1.validateTimeout)(timeout);
// client need to explicitly set the value as 0 to disable eager connection.
if (props.eagerConnectTimeout !== 0) {
await Promise.all(client.dataClients.map(dc => dc.connect(timeout)));
}
return client;
}
catch (e) {
client.close();
throw e;
}
}
/**
* Returns the configuration used to create the CacheClient.
*
* @readonly
* @type {Configuration} - The configuration used to create the CacheClient.
* @memberof CacheClient
*/
get configuration() {
return this._configuration;
}
/**
* Flushes / clears all the items of the given cache
*
* @param {string} cacheName - The cache to be flushed.
* @returns {Promise} -
* {@link CacheFlush.Success} on success.
* {@link CacheFlush.Error} on failure.
*/
async flushCache(cacheName) {
return await this.notYetAbstractedControlClient.flushCache(cacheName);
}
}
exports.CacheClient = CacheClient;
function getDefaultCacheClientConfiguration() {
const config = _1.Configurations.Laptop.latest();
const logger = config.getLoggerFactory().getLogger('CacheClient');
logger.info('No configuration provided to CacheClient. Using default "Laptop" configuration, suitable for development. For production use, consider specifying an explicit configuration.');
return config;
}
/**
* @deprecated use {CacheClient} instead
*/
class SimpleCacheClient extends CacheClient {
}
exports.SimpleCacheClient = SimpleCacheClient;
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiY2FjaGUtY2xpZW50LmpzIiwic291cmNlUm9vdCI6IiIsInNvdXJjZXMiOlsiLi4vLi4vc3JjL2NhY2hlLWNsaWVudC50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiOzs7QUFBQSwwRUFBbUU7QUFDbkUsb0VBQTZEO0FBQzdELHdCQUEyRTtBQUUzRSx1RUFNcUQ7QUFFckQsaUhBQTRHO0FBRTVHLGtEQUFpRTtBQUVqRSxNQUFNLHdDQUF3QyxHQUFHLEVBQUUsQ0FBQztBQUVwRDs7Ozs7OztHQU9HO0FBQ0gsTUFBYSxXQUFZLFNBQVEseUNBQW1CO0lBTWxEOzs7T0FHRztJQUNILFlBQVksS0FBdUI7O1FBQ2pDLElBQUEsMEJBQWtCLEVBQUMsS0FBSyxDQUFDLGlCQUFpQixDQUFDLENBQUM7UUFDNUMsTUFBTSxhQUFhLEdBQ2pCLE1BQUEsS0FBSyxDQUFDLGFBQWEsbUNBQUksa0NBQWtDLEVBQUUsQ0FBQztRQUM5RCxNQUFNLGtCQUFrQixHQUN0QixNQUFBLEtBQUssQ0FBQyxrQkFBa0IsbUNBQUksSUFBQSx1Q0FBNEIsR0FBRSxDQUFDO1FBRTdELE1BQU0sUUFBUSxHQUF3QjtZQUNwQyxHQUFHLEtBQUs7WUFDUixhQUFhLEVBQUUsYUFBYTtZQUM1QixrQkFBa0IsRUFBRSxrQkFBa0I7U0FDdkMsQ0FBQztRQUVGLElBQUksU0FBUyxHQU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