{"id":13809171,"url":"https://github.com/rs/dnscache","last_synced_at":"2025-05-15T09:08:54.014Z","repository":{"id":29760497,"uuid":"117032514","full_name":"rs/dnscache","owner":"rs","description":"DNS lookup cache for Go","archived":false,"fork":false,"pushed_at":"2023-08-04T20:21:42.000Z","size":16,"stargazers_count":277,"open_issues_count":3,"forks_count":38,"subscribers_count":8,"default_branch":"master","last_synced_at":"2025-04-14T15:03:07.228Z","etag":null,"topics":["dns","dns-cache","golang"],"latest_commit_sha":null,"homepage":null,"language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/rs.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null}},"created_at":"2018-01-11T01:21:32.000Z","updated_at":"2025-03-07T14:18:03.000Z","dependencies_parsed_at":"2024-01-07T09:38:02.270Z","dependency_job_id":"8dc0cb7f-4d58-48d2-b2e2-8d00689e8617","html_url":"https://github.com/rs/dnscache","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rs%2Fdnscache","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rs%2Fdnscache/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rs%2Fdnscache/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rs%2Fdnscache/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/rs","download_url":"https://codeload.github.com/rs/dnscache/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":254310520,"owners_count":22049470,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["dns","dns-cache","golang"],"created_at":"2024-08-04T01:02:04.148Z","updated_at":"2025-05-15T09:08:48.993Z","avatar_url":"https://github.com/rs.png","language":"Go","funding_links":[],"categories":["Go"],"sub_categories":[],"readme":"# DNS Lookup Cache\n\n[![license](http://img.shields.io/badge/license-MIT-red.svg?style=flat)](https://raw.githubusercontent.com/rs/dnscache/master/LICENSE)\n[![Go Report Card](https://goreportcard.com/badge/github.com/rs/dnscache)](https://goreportcard.com/report/github.com/rs/dnscache)\n[![Build Status](https://travis-ci.org/rs/dnscache.svg?branch=master)](https://travis-ci.org/rs/dnscache)\n[![Coverage](http://gocover.io/_badge/github.com/rs/dnscache)](http://gocover.io/github.com/rs/dnscache)\n[![godoc](http://img.shields.io/badge/godoc-reference-blue.svg?style=flat)](https://godoc.org/github.com/rs/dnscache)\n\nThe dnscache package provides a DNS cache layer to Go's `net.Resolver`.\n\n# Install\n\nInstall using the \"go get\" command:\n\n```\ngo get -u github.com/rs/dnscache\n```\n\n# Usage\n\nCreate a new instance and use it in place of `net.Resolver`. New names will be cached. Call the `Refresh` method at regular interval to update cached entries and cleanup unused ones.\n\n```go\nresolver := \u0026dnscache.Resolver{}\n\n// First call will cache the result\naddrs, err := resolver.LookupHost(context.Background(), \"example.com\")\n\n// Subsequent calls will use the cached result\naddrs, err = resolver.LookupHost(context.Background(), \"example.com\")\n\n// Call to refresh will refresh names in cache. If you pass true, it will also\n// remove cached names not looked up since the last call to Refresh. It is a good idea\n// to call this method on a regular interval.\ngo func() {\n    t := time.NewTicker(5 * time.Minute)\n    defer t.Stop()\n    for range t.C {\n        resolver.Refresh(true)\n    }\n}()\n```\n\nIf you are using an `http.Transport`, you can use this cache by specifying a `DialContext` function:\n\n```go\nr := \u0026dnscache.Resolver{}\nt := \u0026http.Transport{\n    DialContext: func(ctx context.Context, network string, addr string) (conn net.Conn, err error) {\n        host, port, err := net.SplitHostPort(addr)\n        if err != nil {\n            return nil, err\n        }\n        ips, err := r.LookupHost(ctx, host)\n        if err != nil {\n            return nil, err\n        }\n        for _, ip := range ips {\n            var dialer net.Dialer\n            conn, err = dialer.DialContext(ctx, network, net.JoinHostPort(ip, port))\n            if err == nil {\n                break\n            }\n        }\n        return\n    },\n}\n```\n\nIn addition to the `Refresh` method, you can `RefreshWithOptions`. This method adds an option to persist resource records\non failed lookups\n```go\nr := \u0026Resolver{}\noptions := dnscache.ResolverRefreshOptions{}\noptions.ClearUnused = true\noptions.PersistOnFailure = false\nresolver.RefreshWithOptions(options)\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frs%2Fdnscache","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Frs%2Fdnscache","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frs%2Fdnscache/lists"}