GithubHelp home page GithubHelp logo

dnscache's Introduction

ARCHIVED

dnscache for Node

This module wraps the dns module methods and provide a caching layer in between. Every call to a dns method is first looked into the local cache, in case of cache hit the value from cache is returned, in case of cache miss the original dns call is made and the return value is cached in the local cache.

It is very similar to GOF Proxy design pattern providing a Cache Proxy.

The goal of this module is to cache the most used/most recent dns calls, to avoid the network delay and improve the performance.

Once this module is enabled, all the subsequent calls to require('dns') are wrapped too.

NOTE: There are situations where the built-in dns functions would throw, rather than call back with an error. Due to the fact that asynchronous caching mechanisms are supported, all errors for these functions will be passed as the first argument to the callback.

Installation

npm install dnscache

Usage

var dns = require('dns'),
    dnscache = require('dnscache')({
        "enable" : true,
        "ttl" : 300,
        "cachesize" : 1000
    });
    
    //to use the cached dns either of dnscache or dns can be called.
    //all the methods of dns are wrapped, this one just shows lookup on an example
    
    //will call the wrapped dns
    dnscache.lookup('www.yahoo.com', function(err, result) {
        //do something with result
    });
    
    //will call the wrapped dns
    dns.lookup('www.google.com', function(err, result) {
        //do something with result
    });
    

Configuration

  • enable - Whether dnscache is enabled or not, defaults to false.
  • ttl - ttl in seconds for cache-entries. Default: 300
  • cachesize - number of cache entries, defaults to 1000
  • cache - If a custom cache needs to be used instead of the supplied cache implementation. Only for Advanced Usage. Custom Cache needs to have same interface for get and set.

Advanced Caching

If you want to use a different cache mechanism (ex: mdbm, redis), you only need to create an object similar to this:

var Cache = function(config) {

    this.set = function(key, value, callback) {};

    this.get = function(key, callback) {};
};

Build Status

Build Status

Node Badge

NPM

dnscache's People

Contributors

azetilov avatar bengl avatar cloudrac3r avatar davglass avatar drewfish avatar michaeltrollan avatar nikai3d avatar r-andrew-dev avatar seanparmelee avatar simenb avatar sylvio avatar tangxinfa avatar tikotzky avatar timbowhite avatar vsacheti avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

dnscache's Issues

Incompatibility with node 0.11.14

The family argument in the dns.lookup method is an object and looks like this:
{ family: undefined, hints: 40 }

EDIT: Sorry, i checked wrong version, it already is fixed.

Unable to clear cache

Let's say I cache all the results for an hour. What would happen if you get a bad hostname that the library is not able to resolve for a minute but is available later. Would the bad result be cached for an hour?
Example:
Default config:
dnscache = require('dnscache')({
"enable" : true,
"ttl" : 3600,
"cachesize" : 1000
});
Time 0: Hostname - cannot be resolved
dnscache.lookup(hostname ..) => err (would the bad host be cached?)
Time 5: Hostname - all up and ready to be resolved
dnscache.lookup(hostname ..) => ? (would it pick up from the cache?)

If there is a way you could provide to clean up the cache

If you could add more documentation regarding the use of this library it would be appreciated. Like to return the value we need a callback or a promise based interface. The function is async ..

Ttl cache from DNS server

Hi!
Reading about the possibility to add caching capabilities to nodejs DNS module (which it seems it's not going to happen), there's a comment in this thread with a warning about dnscache module.
Here is the link to the thread.

Here is the comment:

Just to add my two cents in, it is very dangerous to use the dnscache package because it does not respect the ttl set by the dns server. This means that you could potentially have a bad dns cache for some time. By implementing a OS level solution, you'll get all the benefits mentioned above in addition to the reassurance that your dns entries will always be correct.

Is there any chance for this module to respect the TTL set by the DNS server?

Thanks.

support refresh cache perodicly

The dns server of our data center is unstable, so i use dnscache to fix it, and it works most of the time, but when cache expired and dns server is unstable the same time, our service is interrupted until dns server works again.

One solution i think is add a refresh time option(less then ttl time), when cached item not expired but need refresh, resolve it async, update cache if resolve succussfully.

global dnscache

hi,

is this module wrapping the dns function globally in my app and all my node modules in package.json or just for the calls i make in my code?

andreas

Allow to filter which entries to cache

I'm looking for a way to only cache names for a given domain. So I'm thinking having a filter option that takes a regular expression for example, if one wants to cache only hostnames with the example.org domain :

{ filter: /example.org$/ }

Would you take a pull request that implements this ? (Or do you have another suggestion to do the same ?)

Can't catch exception for invalid input

When using Node's dns library you can catch errors for invalid input:

try {
    require('dns').reverse('something wrong', function() {
        console.log('do something');
    });
} catch (e) {
    console.log('some exception happened');
}

Output: some exception happened

Doing this with dnscache:

dns.js:156
      throw errnoException(process._errno, bindingName);
            ^
Error: getHostByAddr ENOTIMP
    at errnoException (dns.js:37:11)
    at Object.query [as reverse] (dns.js:156:13)
    at C:\work\temp\node_modules\dnscache\lib\index.js:285:35
    at Object._onImmediate (C:\work\temp\node_modules\dnscache\lib\cache.js:121:21)
    at processImmediate [as _immediateCallback] (timers.js:354:15)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.