44 "log"
55 "net/http"
66 "sync"
7+ "time"
78
89 "certui/internal/certificate"
910 "certui/internal/domain"
@@ -16,8 +17,24 @@ type EndpointDetails struct {
1617 SSL * certificate.SSLDetails
1718}
1819
20+ const endpointCacheTTL = time .Hour
21+
22+ var endpointCache sync.Map // map[domain.Domain]endpointCacheEntry
23+
24+ type endpointCacheEntry struct {
25+ details * EndpointDetails
26+ expiresAt time.Time
27+ }
28+
1929// fetchEndpointDetails fetches certificate, domain, and WHOIS details concurrently for a single endpoint
2030func fetchEndpointDetails (client * http.Client , endpoint domain.Domain ) * EndpointDetails {
31+ if v , ok := endpointCache .Load (endpoint ); ok {
32+ entry := v .(endpointCacheEntry )
33+ if time .Now ().Before (entry .expiresAt ) {
34+ return entry .details
35+ }
36+ }
37+
2138 var ssl * certificate.SSLDetails
2239 var domainDetails domain.DomainDetails
2340 var whoisDetails * domain.WhoisDetails
@@ -46,5 +63,10 @@ func fetchEndpointDetails(client *http.Client, endpoint domain.Domain) *Endpoint
4663 }()
4764 wg .Wait ()
4865
49- return & EndpointDetails {Domain : domainDetails , Whois : whoisDetails , SSL : ssl }
66+ details := & EndpointDetails {Domain : domainDetails , Whois : whoisDetails , SSL : ssl }
67+ endpointCache .Store (endpoint , endpointCacheEntry {
68+ details : details ,
69+ expiresAt : time .Now ().Add (endpointCacheTTL ),
70+ })
71+ return details
5072}
0 commit comments