Skip to main content


DNS lookup cache for Node.js - cacheable-lookup library integration.


DNS lookup cache can speed up your server-side HTTP requests to external API's.

Usually, DNS lookup is a fast process, but Node.js (libuv under the hood) has a default limit of 4 concurrent threads, used for a set of synchronous operations, including DNS lookup, so lookup can be queued. Or if application is under high load, or while any network problems, DNS lookup time can be increased.

First main optimization of HTTP connections is already used in tramvai HTTP clients - keepAlive option for http and https agents. With keepAlive, TCP sockets are reused for multiple HTTP requests, and count of DNS lookups is decreased dramatically.

Because of that, DNS cache it's a nice and cheap optimization, but don't expect some huge performance boost.

Potential disadvantages - external services can change their IP addresses, and HTTP requests will use outdated DNS cache, you can detect some of this errors by search ECONNRESET errors is server logs, so long cache TTL is not recommended.


You need to install @tramvai/module-dns-cache module:

npx tramvai add @tramvai/module-dns-cache

Then, connect TramvaiDnsCacheModule from this package to createApp function:

import { createApp } from '@tramvai/core';
import { TramvaiDnsCacheModule } from '@tramvai/module-dns-cache';

name: 'tincoin',
modules: [TramvaiDnsCacheModule],



By default, DNS lookup cache is enabled.

To disable it, you need to provide DNS_LOOKUP_CACHE_ENABLE environment variable:


Cache TTL

Default TTL for DNS lookup cache is 60 seconds. You can change it by providing DNS_LOOKUP_CACHE_TTL environment variable:


Cache size

Default cache size is 200 entries. You can change it by providing DNS_LOOKUP_CACHE_LIMIT environment variable: