Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix caching #5

Open
pforemski opened this issue Oct 13, 2016 · 1 comment
Open

fix caching #5

pforemski opened this issue Oct 13, 2016 · 1 comment

Comments

@pforemski
Copy link
Owner

Currently, dingo just caches DNS rrsets for 10 seconds, which generally isn't a bug, but is largely suboptimal in many cases.

@pforemski pforemski modified the milestone: dingo 0.12 Oct 13, 2016
@ghost
Copy link

ghost commented Jul 18, 2017

Implemented TTLs in cache like this seems to work,
I wish there was a way that didn't involve looping through all answers

        /* check cache */
        var r Reply
        cid := fmt.Sprintf("%s/%d", qname, qtype)
        if x, found := rcache.Get(cid); found {
                r = x.(Reply)
                dbg(8, "cache hit: %+v", r)
                /* Just because we get a hit doesn't mean we should refresh TTL */
        } else {
                /* pass to resolvers and block until the response comes */
                r = resolve(qname, int(qtype))
                dbg(8, "got reply: %+v", r)

                if (r.Status >= 0) {
                        var lowestTtl uint32 = 3600
                        for _,grr := range r.Answer {
                                if grr.TTL < lowestTtl {
                                        lowestTtl = grr.TTL
                                }
                        }
                        for _,grr := range r.Authority {
                                if grr.TTL < lowestTtl {
                                        lowestTtl = grr.TTL
                                }
                        }
                        dbg(4, "Updating cache: TTL: %d, payload: %+v", lowestTtl, r)
                        /* Update Cache, and use real TTL as timeout */
                        rcache.Set(cid, r, time.Duration(lowestTtl)*time.Second)
                }
        }

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant