Prevent multiple IP lookups
This commit is contained in:
parent
25b7e39d75
commit
339bac921f
@ -2,15 +2,20 @@ package middleware
|
||||
|
||||
import (
|
||||
"net"
|
||||
"sync"
|
||||
"time"
|
||||
|
||||
cache "github.com/patrickmn/go-cache"
|
||||
)
|
||||
|
||||
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).
|
||||
func GetHostsForIP(ip string) ([]string, bool) {
|
||||
ipToHostsMutex.Lock()
|
||||
defer ipToHostsMutex.Unlock()
|
||||
|
||||
hosts, found := ipToHosts.Get(ip)
|
||||
|
||||
if !found {
|
||||
|
Loading…
Reference in New Issue
Block a user