How to use cacheable-lookup - 1 common examples

To help you get started, we’ve selected a few cacheable-lookup examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github sindresorhus / got / source / normalize-arguments.ts View on Github external
options.retry.limit = retry;
	}

	if (options.retry.maxRetryAfter === undefined) {
		options.retry.maxRetryAfter = Math.min(
			...[options.timeout.request, options.timeout.connect].filter((n): n is number => !is.nullOrUndefined(n))
		);
	}

	options.retry.methods = [...new Set(options.retry.methods!.map(method => method.toUpperCase() as Method))];
	options.retry.statusCodes = [...new Set(options.retry.statusCodes)];
	options.retry.errorCodes = [...new Set(options.retry.errorCodes)];

	// `options.dnsCache`
	if (options.dnsCache && !(options.dnsCache instanceof CacheableLookup)) {
		options.dnsCache = new CacheableLookup({cacheAdapter: options.dnsCache as Keyv});
	}

	// `options.method`
	if (is.string(options.method)) {
		options.method = options.method.toUpperCase() as Method;
	} else {
		options.method = defaults?.method ?? 'GET';
	}

	// Better memory management, so we don't have to generate a new object every time
	if (options.cache) {
		(options as NormalizedOptions).cacheableRequest = new CacheableRequest(
			// @ts-ignore Cannot properly type a function with multiple definitions yet
			(requestOptions, handler) => requestOptions.request(requestOptions, handler),
			options.cache
		);

cacheable-lookup

A cacheable dns.lookup(…) that respects TTL

MIT
Latest version published 2 years ago

Package Health Score

77 / 100
Full package analysis

Popular cacheable-lookup functions