Prevent multiple IP lookups
This commit is contained in:
parent
25b7e39d75
commit
339bac921f
@ -2,15 +2,20 @@ package middleware
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"net"
|
"net"
|
||||||
|
"sync"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
cache "github.com/patrickmn/go-cache"
|
cache "github.com/patrickmn/go-cache"
|
||||||
)
|
)
|
||||||
|
|
||||||
var ipToHosts = cache.New(60*time.Minute, 30*time.Minute)
|
var ipToHosts = cache.New(60*time.Minute, 30*time.Minute)
|
||||||
|
var ipToHostsMutex sync.Mutex
|
||||||
|
|
||||||
// GetHostsForIP returns all host names for the given IP (if cached).
|
// GetHostsForIP returns all host names for the given IP (if cached).
|
||||||
func GetHostsForIP(ip string) ([]string, bool) {
|
func GetHostsForIP(ip string) ([]string, bool) {
|
||||||
|
ipToHostsMutex.Lock()
|
||||||
|
defer ipToHostsMutex.Unlock()
|
||||||
|
|
||||||
hosts, found := ipToHosts.Get(ip)
|
hosts, found := ipToHosts.Get(ip)
|
||||||
|
|
||||||
if !found {
|
if !found {
|
||||||
|
Loading…
Reference in New Issue
Block a user