npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

@eggjs/tegg-dns-cache

v3.68.0

Published

tegg dns cache plugin

Readme

@eggjs/tegg-dns-cache

DNS cache plugin for tegg framework. This plugin provides DNS caching capabilities to improve performance and reduce DNS lookup time.

Features

  • 🚀 DNS lookup caching with LRU algorithm
  • ⚖️ Round-robin address rotation for load balancing
  • 🔄 Support both dns.lookup and dns.resolve modes
  • ⏱️ Configurable cache TTL
  • 🔌 Automatic integration with egg httpclient
  • 🎯 Custom DNS nameservers support

Installation

npm install @eggjs/tegg-dns-cache --save

Usage

Enable Plugin

// config/plugin.js
exports.dnsCache = {
  enable: true,
  package: '@eggjs/tegg-dns-cache',
};

Configuration

// config/config.default.js
exports.dnsCache = {
  // DNS resolution mode: 'lookup' or 'resolve' (default: 'resolve')
  // - lookup: Use dns.lookup, respects /etc/hosts, but no TTL support
  // - resolve: Use dns.resolve, queries DNS directly, TTL supported
  mode: 'resolve',
  
  // Custom DNS nameservers (only for 'resolve' mode)
  dnsServers: ['8.8.8.8', '1.1.1.1'],
  
  // Maximum cache entries (default: 1000)
  maxCacheLength: 1000,
  
  // Cache lookup interval in ms (only for 'lookup' mode, default: 10000)
  lookupInterval: 10000,
  
  // Enable address rotation for multiple IPs (default: true)
  addressRotation: true,
};

DNS Resolution Modes

Resolve Mode (Recommended)

Uses dns.resolve4() to query DNS servers directly. Supports TTL from DNS records.

Advantages:

  • Respects DNS TTL from authoritative servers
  • More control over DNS resolution
  • Can specify custom nameservers

Note: Does not respect /etc/hosts file.

exports.dnsCache = {
  mode: 'resolve',
  dnsServers: ['8.8.8.8', '1.1.1.1'], // Optional custom DNS servers
};

Lookup Mode

Uses dns.lookup() which respects system DNS configuration and /etc/hosts.

Advantages:

  • Respects /etc/hosts entries
  • Uses system DNS configuration

Disadvantages:

  • Fixed cache interval (no real TTL)
  • Less control over resolution
exports.dnsCache = {
  mode: 'lookup',
  lookupInterval: 10000, // Cache refresh interval in ms
};

API

Access DNS Resolver

// In controller or service
const resolver = this.app.dnsResolver;

// Get cached DNS record
const record = resolver.getCacheRecord('example.com');
console.log(record); // { ip: '93.184.216.34', family: 4, ttl: 60000, ... }

// Clear DNS cache
resolver.resetCache();

// Get the underlying LRU cache
const cache = resolver.getDnsCache();

Address Rotation

When a hostname resolves to multiple IP addresses, the plugin can automatically rotate through them for load balancing:

exports.dnsCache = {
  addressRotation: true, // Enable round-robin rotation
};

Each request to the same hostname will use the next IP address in rotation.

Integration with HttpClient

The plugin automatically integrates with egg's built-in httpclient. All HTTP requests will benefit from DNS caching:

// This request will use cached DNS
await this.app.httpclient.request('https://example.com/api');

Performance Benefits

  • Reduced DNS lookup time: Cached DNS results eliminate network round trips
  • Lower DNS server load: Fewer queries to DNS servers
  • Improved request throughput: Faster connection establishment
  • Load distribution: Address rotation spreads load across multiple IPs

License

MIT