Use hashicorp's LRU cache for DNS & certificates

DNS caching is also limited to 30 seconds now instead of 5 minutes
This commit is contained in:
Moritz Marquardt 2024-04-16 22:22:09 +02:00
parent 7694deec83
commit 18d09a163c
8 changed files with 49 additions and 36 deletions

View file

@ -11,7 +11,6 @@ import (
"strings"
"time"
"github.com/OrlovEvgeny/go-mcache"
"github.com/redis/go-redis/v9"
"github.com/rs/zerolog"
@ -73,11 +72,6 @@ func Serve(ctx *cli.Context) error {
}
defer closeFn()
// keyCache stores the parsed certificate objects (Redis is no advantage here)
keyCache := mcache.New()
// dnsLookupCache stores DNS lookups for custom domains (Redis is no advantage here)
dnsLookupCache := mcache.New()
var redisErr error = nil
createCache := func(name string) cache.ICache {
if cfg.Cache.RedisURL != "" {
@ -129,7 +123,7 @@ func Serve(ctx *cli.Context) error {
giteaClient,
acmeClient,
cfg.Server.PagesBranches[0],
keyCache, challengeCache, dnsLookupCache, canonicalDomainCache,
challengeCache, canonicalDomainCache,
certDB,
cfg.ACME.NoDNS01,
cfg.Server.RawDomain,
@ -155,7 +149,7 @@ func Serve(ctx *cli.Context) error {
}
// Create ssl handler based on settings
sslHandler := handler.Handler(cfg.Server, giteaClient, dnsLookupCache, canonicalDomainCache, redirectsCache)
sslHandler := handler.Handler(cfg.Server, giteaClient, canonicalDomainCache, redirectsCache)
// Start the ssl listener
log.Info().Msgf("Start SSL server using TCP listener on %s", listener.Addr())