From 8f20bd3840587492c5a565c67b2ec70d7f92d862 Mon Sep 17 00:00:00 2001 From: yusing Date: Sat, 26 Apr 2025 08:05:26 +0800 Subject: [PATCH] fix(acl): caching logic --- internal/acl/city_cache.go | 4 +--- internal/acl/config.go | 2 +- 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/internal/acl/city_cache.go b/internal/acl/city_cache.go index 1c496d5..f18b0fc 100644 --- a/internal/acl/city_cache.go +++ b/internal/acl/city_cache.go @@ -3,11 +3,9 @@ package acl import ( "github.com/puzpuzpuz/xsync/v3" acl "github.com/yusing/go-proxy/internal/acl/types" - "go.uber.org/atomic" ) var cityCache = xsync.NewMapOf[string, *acl.City]() -var numCachedLookup atomic.Uint64 func (cfg *MaxMindConfig) lookupCity(ip *acl.IPInfo) (*acl.City, bool) { if ip.City != nil { @@ -20,7 +18,7 @@ func (cfg *MaxMindConfig) lookupCity(ip *acl.IPInfo) (*acl.City, bool) { city, ok := cityCache.Load(ip.Str) if ok { - numCachedLookup.Inc() + ip.City = city return city, true } diff --git a/internal/acl/config.go b/internal/acl/config.go index e56cbc0..b47bfd4 100644 --- a/internal/acl/config.go +++ b/internal/acl/config.go @@ -63,7 +63,7 @@ type checkCache struct { const cacheTTL = 1 * time.Minute func (c *checkCache) Expired() bool { - return c.created.Add(cacheTTL).After(utils.TimeNow()) + return c.created.Add(cacheTTL).Before(utils.TimeNow()) } //TODO: add stats