From db1d4c55a985fde03fe1f8e7936b1bd87df73b51 Mon Sep 17 00:00:00 2001 From: AJ ONeal Date: Thu, 10 Sep 2026 02:08:36 -0600 Subject: [PATCH] refactor(sync): rename cacheable package --- cmd/check-ip/go.mod | 2 +- cmd/check-ip/go.sum | 4 ++-- cmd/form2mail/go.mod | 2 +- cmd/form2mail/go.sum | 4 ++-- net/formmailer/go.mod | 2 +- net/formmailer/go.sum | 4 ++-- net/geoip/fetch.go | 16 ++++++++-------- net/geoip/go.mod | 2 +- net/geoip/go.sum | 4 ++-- net/iplist/go.mod | 2 +- net/iplist/go.sum | 4 ++-- net/iplist/source.go | 16 ++++++++-------- net/ippolicy/domains.go | 9 +++++++-- net/ippolicy/go.mod | 2 +- net/ippolicy/go.sum | 4 ++-- net/ippolicy/ipprefix.go | 16 ++++++++-------- sync/cachable/go.mod | 3 --- sync/{cachable => cacheable}/cacheable.go | 4 ++-- sync/cacheable/go.mod | 3 +++ sync/{cachable => cacheable}/refresh.go | 2 +- sync/{cachable => cacheable}/refresh_test.go | 2 +- sync/dataset/dataset.go | 18 +++++++++--------- sync/dataset/go.mod | 2 +- sync/dataset/go.sum | 4 ++-- 24 files changed, 68 insertions(+), 63 deletions(-) delete mode 100644 sync/cachable/go.mod rename sync/{cachable => cacheable}/cacheable.go (92%) create mode 100644 sync/cacheable/go.mod rename sync/{cachable => cacheable}/refresh.go (99%) rename sync/{cachable => cacheable}/refresh_test.go (99%) diff --git a/cmd/check-ip/go.mod b/cmd/check-ip/go.mod index c95bffd..f8e35d3 100644 --- a/cmd/check-ip/go.mod +++ b/cmd/check-ip/go.mod @@ -14,7 +14,7 @@ require ( github.com/oschwald/geoip2-golang v1.13.0 // indirect github.com/oschwald/maxminddb-golang v1.13.0 // indirect github.com/therootcompany/golib/https v0.9.0 // indirect - github.com/therootcompany/golib/sync/cachable v0.1.0 // indirect + github.com/therootcompany/golib/sync/cacheable v0.1.0 // indirect golang.org/x/sync v0.20.0 // indirect golang.org/x/sys v0.45.0 // indirect ) diff --git a/cmd/check-ip/go.sum b/cmd/check-ip/go.sum index 7f4a8d9..447ac4c 100644 --- a/cmd/check-ip/go.sum +++ b/cmd/check-ip/go.sum @@ -18,8 +18,8 @@ github.com/therootcompany/golib/net/httpcache v0.6.0 h1:qFBnSs6rZrtUQ+fweP4bHF2F github.com/therootcompany/golib/net/httpcache v0.6.0/go.mod h1:mKSQJWpGSCDBzWkTCwT7dO1SCVCsFmdkRgKr39fNS1U= github.com/therootcompany/golib/net/ipcohort v0.9.0 h1:j3AaoW2u4XQJz1ya6fixv3pb3KgxIpZV8t0082/kS3E= github.com/therootcompany/golib/net/ipcohort v0.9.0/go.mod h1:Ljcnt2xOryVDGIVV5Kzt5hj2LhW4lBAWo5OeeVYU9ys= -github.com/therootcompany/golib/sync/cachable v0.1.0 h1:swCXtXB116jhSmla81HaXi/9cPsqFI+Oq/6OcSfdU5Q= -github.com/therootcompany/golib/sync/cachable v0.1.0/go.mod h1:l/NZdGiSbW5CkLlkkRa0yObkqak2sj/jQTXXqXwvCl0= +github.com/therootcompany/golib/sync/cacheable v0.1.0 h1:swCXtXB116jhSmla81HaXi/9cPsqFI+Oq/6OcSfdU5Q= +github.com/therootcompany/golib/sync/cacheable v0.1.0/go.mod h1:l/NZdGiSbW5CkLlkkRa0yObkqak2sj/jQTXXqXwvCl0= github.com/therootcompany/golib/sync/dataset v0.6.0 h1:Gerq315Ld1PyfD+6EmTDxSEAOg6s0kDchL2oo/jAQZ0= github.com/therootcompany/golib/sync/dataset v0.6.0/go.mod h1:ktn0ppeIpNvgNLFYFuD9W6hGEQfwaIEcE8TV048+Y9M= golang.org/x/sync v0.20.0 h1:e0PTpb7pjO8GAtTs2dQ6jYa5BWYlMuX047Dco/pItO4= diff --git a/cmd/form2mail/go.mod b/cmd/form2mail/go.mod index 375cf4b..916aae7 100644 --- a/cmd/form2mail/go.mod +++ b/cmd/form2mail/go.mod @@ -21,7 +21,7 @@ require ( github.com/therootcompany/golib/net/ipcohort v0.9.0 // indirect github.com/therootcompany/golib/net/iplist v0.9.1 // indirect github.com/therootcompany/golib/net/ippolicy v0.9.1 // indirect - github.com/therootcompany/golib/sync/cachable v0.1.0 // indirect + github.com/therootcompany/golib/sync/cacheable v0.1.0 // indirect golang.org/x/mod v0.30.0 // indirect golang.org/x/net v0.47.0 // indirect golang.org/x/sync v0.20.0 // indirect diff --git a/cmd/form2mail/go.sum b/cmd/form2mail/go.sum index e1ba647..cfdd11b 100644 --- a/cmd/form2mail/go.sum +++ b/cmd/form2mail/go.sum @@ -34,8 +34,8 @@ github.com/therootcompany/golib/net/iplist v0.9.1 h1:atyzk6RPSPP/E+2Y+Q1XzBs3GnD github.com/therootcompany/golib/net/iplist v0.9.1/go.mod h1:8ifRSgp4ptijldClyh688NLom8EZre6E16JZ2AHCEMw= github.com/therootcompany/golib/net/ippolicy v0.9.1 h1:szAPNGFaJyD44MRSQ3r+AXOVdRVaoS8rMob44V8UbUk= github.com/therootcompany/golib/net/ippolicy v0.9.1/go.mod h1:3FpLflMoNLpHlE2XgHaXTekFHgg3BBRFqkOm+9hvosQ= -github.com/therootcompany/golib/sync/cachable v0.1.0 h1:swCXtXB116jhSmla81HaXi/9cPsqFI+Oq/6OcSfdU5Q= -github.com/therootcompany/golib/sync/cachable v0.1.0/go.mod h1:l/NZdGiSbW5CkLlkkRa0yObkqak2sj/jQTXXqXwvCl0= +github.com/therootcompany/golib/sync/cacheable v0.1.0 h1:swCXtXB116jhSmla81HaXi/9cPsqFI+Oq/6OcSfdU5Q= +github.com/therootcompany/golib/sync/cacheable v0.1.0/go.mod h1:l/NZdGiSbW5CkLlkkRa0yObkqak2sj/jQTXXqXwvCl0= golang.org/x/mod v0.30.0 h1:fDEXFVZ/fmCKProc/yAXXUijritrDzahmwwefnjoPFk= golang.org/x/mod v0.30.0/go.mod h1:lAsf5O2EvJeSFMiBxXDki7sCgAxEUcZHXoXMKT4GJKc= golang.org/x/net v0.47.0 h1:Mx+4dIFzqraBXUugkia1OOvlD6LemFo1ALMHjrXDOhY= diff --git a/net/formmailer/go.mod b/net/formmailer/go.mod index 76d8701..1105665 100644 --- a/net/formmailer/go.mod +++ b/net/formmailer/go.mod @@ -19,7 +19,7 @@ require ( github.com/therootcompany/golib/net/httpcache v0.6.0 // indirect github.com/therootcompany/golib/net/ipcohort v0.9.0 // indirect github.com/therootcompany/golib/net/iplist v0.9.1 // indirect - github.com/therootcompany/golib/sync/cachable v0.1.0 // indirect + github.com/therootcompany/golib/sync/cacheable v0.1.0 // indirect golang.org/x/mod v0.30.0 // indirect golang.org/x/net v0.47.0 // indirect golang.org/x/sync v0.20.0 // indirect diff --git a/net/formmailer/go.sum b/net/formmailer/go.sum index 0106850..05b7693 100644 --- a/net/formmailer/go.sum +++ b/net/formmailer/go.sum @@ -30,8 +30,8 @@ github.com/therootcompany/golib/net/iplist v0.9.1 h1:atyzk6RPSPP/E+2Y+Q1XzBs3GnD github.com/therootcompany/golib/net/iplist v0.9.1/go.mod h1:8ifRSgp4ptijldClyh688NLom8EZre6E16JZ2AHCEMw= github.com/therootcompany/golib/net/ippolicy v0.9.1 h1:szAPNGFaJyD44MRSQ3r+AXOVdRVaoS8rMob44V8UbUk= github.com/therootcompany/golib/net/ippolicy v0.9.1/go.mod h1:3FpLflMoNLpHlE2XgHaXTekFHgg3BBRFqkOm+9hvosQ= -github.com/therootcompany/golib/sync/cachable v0.1.0 h1:swCXtXB116jhSmla81HaXi/9cPsqFI+Oq/6OcSfdU5Q= -github.com/therootcompany/golib/sync/cachable v0.1.0/go.mod h1:l/NZdGiSbW5CkLlkkRa0yObkqak2sj/jQTXXqXwvCl0= +github.com/therootcompany/golib/sync/cacheable v0.1.0 h1:swCXtXB116jhSmla81HaXi/9cPsqFI+Oq/6OcSfdU5Q= +github.com/therootcompany/golib/sync/cacheable v0.1.0/go.mod h1:l/NZdGiSbW5CkLlkkRa0yObkqak2sj/jQTXXqXwvCl0= golang.org/x/mod v0.30.0 h1:fDEXFVZ/fmCKProc/yAXXUijritrDzahmwwefnjoPFk= golang.org/x/mod v0.30.0/go.mod h1:lAsf5O2EvJeSFMiBxXDki7sCgAxEUcZHXoXMKT4GJKc= golang.org/x/net v0.47.0 h1:Mx+4dIFzqraBXUugkia1OOvlD6LemFo1ALMHjrXDOhY= diff --git a/net/geoip/fetch.go b/net/geoip/fetch.go index 6c013c8..892a837 100644 --- a/net/geoip/fetch.go +++ b/net/geoip/fetch.go @@ -13,7 +13,7 @@ import ( "github.com/therootcompany/golib/https" "github.com/therootcompany/golib/net/httpcache" - "github.com/therootcompany/golib/sync/cachable" + "github.com/therootcompany/golib/sync/cacheable" ) const ( @@ -43,7 +43,7 @@ type GeoIPDB struct { cancel context.CancelFunc loadedAt atomic.Pointer[time.Time] lastErr atomic.Pointer[error] - refresh cachable.Refresh + refresh cacheable.Refresh local bool } @@ -105,10 +105,10 @@ func (f *GeoIPDB) ready() error { // Fetch downloads all configured editions and reports whether any changed. var ( - _ cachable.Cacheable[Databases] = (*GeoIPDB)(nil) - _ cachable.Mutable[Databases] = (*GeoIPDB)(nil) - _ cachable.Inspectable = (*GeoIPDB)(nil) - _ cachable.Tickable = (*GeoIPDB)(nil) + _ cacheable.Cacheable[Databases] = (*GeoIPDB)(nil) + _ cacheable.Mutable[Databases] = (*GeoIPDB)(nil) + _ cacheable.Inspectable = (*GeoIPDB)(nil) + _ cacheable.Tickable = (*GeoIPDB)(nil) ) // Current returns the newest completed City+ASN snapshot without blocking. @@ -195,7 +195,7 @@ func (f *GeoIPDB) Clear() error { return f.Set(nil) } -func (f *GeoIPDB) Status() cachable.Status { +func (f *GeoIPDB) Status() cacheable.Status { loadedAt := time.Time{} if t := f.loadedAt.Load(); t != nil { loadedAt = *t @@ -204,7 +204,7 @@ func (f *GeoIPDB) Status() cachable.Status { if p := f.lastErr.Load(); p != nil { lastErr = *p } - status := cachable.Status{LoadedAt: loadedAt, HasValue: f.Current() != nil, Refreshing: f.refresh.Running(), LastError: lastErr} + status := cacheable.Status{LoadedAt: loadedAt, HasValue: f.Current() != nil, Refreshing: f.refresh.Running(), LastError: lastErr} if !loadedAt.IsZero() && f.maxAge > 0 { status.StaleAt = loadedAt.Add(f.maxAge) } diff --git a/net/geoip/go.mod b/net/geoip/go.mod index 5bcd297..2bb78d0 100644 --- a/net/geoip/go.mod +++ b/net/geoip/go.mod @@ -6,7 +6,7 @@ require ( github.com/oschwald/geoip2-golang v1.13.0 github.com/therootcompany/golib/https v0.9.0 github.com/therootcompany/golib/net/httpcache v0.6.0 - github.com/therootcompany/golib/sync/cachable v0.1.0 + github.com/therootcompany/golib/sync/cacheable v0.1.0 ) require ( diff --git a/net/geoip/go.sum b/net/geoip/go.sum index 4fe6d44..23e6c63 100644 --- a/net/geoip/go.sum +++ b/net/geoip/go.sum @@ -12,8 +12,8 @@ github.com/therootcompany/golib/https v0.9.0 h1:D9gh0K6ljkvF805JUbylITn8SHPMo08q github.com/therootcompany/golib/https v0.9.0/go.mod h1:ilExqR/Uh7oB36oy9mwuNhANcFh+zdCfD3uJiZ11YAY= github.com/therootcompany/golib/net/httpcache v0.6.0 h1:qFBnSs6rZrtUQ+fweP4bHF2FQd/Syvs7mRN5nO5YtkY= github.com/therootcompany/golib/net/httpcache v0.6.0/go.mod h1:mKSQJWpGSCDBzWkTCwT7dO1SCVCsFmdkRgKr39fNS1U= -github.com/therootcompany/golib/sync/cachable v0.1.0 h1:swCXtXB116jhSmla81HaXi/9cPsqFI+Oq/6OcSfdU5Q= -github.com/therootcompany/golib/sync/cachable v0.1.0/go.mod h1:l/NZdGiSbW5CkLlkkRa0yObkqak2sj/jQTXXqXwvCl0= +github.com/therootcompany/golib/sync/cacheable v0.1.0 h1:swCXtXB116jhSmla81HaXi/9cPsqFI+Oq/6OcSfdU5Q= +github.com/therootcompany/golib/sync/cacheable v0.1.0/go.mod h1:l/NZdGiSbW5CkLlkkRa0yObkqak2sj/jQTXXqXwvCl0= golang.org/x/sync v0.20.0 h1:e0PTpb7pjO8GAtTs2dQ6jYa5BWYlMuX047Dco/pItO4= golang.org/x/sync v0.20.0/go.mod h1:9xrNwdLfx4jkKbNva9FpL6vEN7evnE43NNNJQ2LF3+0= golang.org/x/sys v0.45.0 h1:dO4czNzziLiiXplLQgBCEpCvXQ3dnkn0SdaZSYdQ+FY= diff --git a/net/iplist/go.mod b/net/iplist/go.mod index 2405e31..b3319ab 100644 --- a/net/iplist/go.mod +++ b/net/iplist/go.mod @@ -6,7 +6,7 @@ require ( github.com/therootcompany/golib/https v0.9.0 github.com/therootcompany/golib/io/transform/gsheet2csv v1.1.0 github.com/therootcompany/golib/net/httpcache v0.6.0 - github.com/therootcompany/golib/sync/cachable v0.1.0 + github.com/therootcompany/golib/sync/cacheable v0.1.0 ) require golang.org/x/sync v0.20.0 // indirect diff --git a/net/iplist/go.sum b/net/iplist/go.sum index 601d233..2d492ac 100644 --- a/net/iplist/go.sum +++ b/net/iplist/go.sum @@ -4,7 +4,7 @@ github.com/therootcompany/golib/io/transform/gsheet2csv v1.1.0 h1:R5zAPun5p3JPlN github.com/therootcompany/golib/io/transform/gsheet2csv v1.1.0/go.mod h1:CsntOAhhIMdzSAYuwuRZtfkdoiER9+TfSgYOIDWN71o= github.com/therootcompany/golib/net/httpcache v0.6.0 h1:qFBnSs6rZrtUQ+fweP4bHF2FQd/Syvs7mRN5nO5YtkY= github.com/therootcompany/golib/net/httpcache v0.6.0/go.mod h1:mKSQJWpGSCDBzWkTCwT7dO1SCVCsFmdkRgKr39fNS1U= -github.com/therootcompany/golib/sync/cachable v0.1.0 h1:swCXtXB116jhSmla81HaXi/9cPsqFI+Oq/6OcSfdU5Q= -github.com/therootcompany/golib/sync/cachable v0.1.0/go.mod h1:l/NZdGiSbW5CkLlkkRa0yObkqak2sj/jQTXXqXwvCl0= +github.com/therootcompany/golib/sync/cacheable v0.1.0 h1:swCXtXB116jhSmla81HaXi/9cPsqFI+Oq/6OcSfdU5Q= +github.com/therootcompany/golib/sync/cacheable v0.1.0/go.mod h1:l/NZdGiSbW5CkLlkkRa0yObkqak2sj/jQTXXqXwvCl0= golang.org/x/sync v0.20.0 h1:e0PTpb7pjO8GAtTs2dQ6jYa5BWYlMuX047Dco/pItO4= golang.org/x/sync v0.20.0/go.mod h1:9xrNwdLfx4jkKbNva9FpL6vEN7evnE43NNNJQ2LF3+0= diff --git a/net/iplist/source.go b/net/iplist/source.go index a2ef95f..50c7296 100644 --- a/net/iplist/source.go +++ b/net/iplist/source.go @@ -10,7 +10,7 @@ import ( "sync/atomic" "time" - "github.com/therootcompany/golib/sync/cachable" + "github.com/therootcompany/golib/sync/cacheable" ) const ( @@ -36,14 +36,14 @@ type IPList struct { generation atomic.Uint64 loadedAt atomic.Pointer[time.Time] lastErr atomic.Pointer[error] - refresh cachable.Refresh + refresh cacheable.Refresh } var ( - _ cachable.Cacheable[[]string] = (*IPList)(nil) - _ cachable.Mutable[[]string] = (*IPList)(nil) - _ cachable.Inspectable = (*IPList)(nil) - _ cachable.Tickable = (*IPList)(nil) + _ cacheable.Cacheable[[]string] = (*IPList)(nil) + _ cacheable.Mutable[[]string] = (*IPList)(nil) + _ cacheable.Inspectable = (*IPList)(nil) + _ cacheable.Tickable = (*IPList)(nil) ) func NewIPList(ctx context.Context, config IPListConfig) (*IPList, error) { @@ -137,7 +137,7 @@ func (s *IPList) Clear() error { return nil } -func (s *IPList) Status() cachable.Status { +func (s *IPList) Status() cacheable.Status { loadedAt := time.Time{} if t := s.loadedAt.Load(); t != nil { loadedAt = *t @@ -146,7 +146,7 @@ func (s *IPList) Status() cachable.Status { if p := s.lastErr.Load(); p != nil { lastErr = *p } - status := cachable.Status{LoadedAt: loadedAt, HasValue: s.Current() != nil, Refreshing: s.refresh.Running(), LastError: lastErr} + status := cacheable.Status{LoadedAt: loadedAt, HasValue: s.Current() != nil, Refreshing: s.refresh.Running(), LastError: lastErr} if !loadedAt.IsZero() { status.StaleAt = loadedAt.Add(s.config.RefreshInterval) } diff --git a/net/ippolicy/domains.go b/net/ippolicy/domains.go index efa6dd2..7f4c2be 100644 --- a/net/ippolicy/domains.go +++ b/net/ippolicy/domains.go @@ -11,7 +11,7 @@ import ( "github.com/therootcompany/golib/net/dnsresolver" "github.com/therootcompany/golib/net/ipcohort" - "github.com/therootcompany/golib/sync/cachable" + "github.com/therootcompany/golib/sync/cacheable" ) const DefaultDomainSetRefreshInterval = 5 * time.Minute @@ -95,7 +95,12 @@ func (ds *DomainSet) Replace(staticPrefixes, domains []string) { ds.rebuildCohort() } -var _ cachable.Tickable = (*DomainSet)(nil) +var _ cacheable.Tickable = (*DomainSet)(nil) + +// Current returns the current immutable address cohort. +func (ds *DomainSet) Current() *ipcohort.Cohort { + return ds.cohort.Load() +} // Start starts at most one optional background DNS refresh ticker. func (ds *DomainSet) Start(ctx context.Context, interval time.Duration) { diff --git a/net/ippolicy/go.mod b/net/ippolicy/go.mod index d1a8e4e..d4a719b 100644 --- a/net/ippolicy/go.mod +++ b/net/ippolicy/go.mod @@ -7,7 +7,7 @@ require ( github.com/therootcompany/golib/net/gitshallow v0.10.0 github.com/therootcompany/golib/net/ipcohort v0.9.0 github.com/therootcompany/golib/net/iplist v0.9.1 - github.com/therootcompany/golib/sync/cachable v0.1.0 + github.com/therootcompany/golib/sync/cacheable v0.1.0 ) require ( diff --git a/net/ippolicy/go.sum b/net/ippolicy/go.sum index 2afba84..4c87a37 100644 --- a/net/ippolicy/go.sum +++ b/net/ippolicy/go.sum @@ -16,8 +16,8 @@ github.com/therootcompany/golib/net/ipcohort v0.9.0 h1:j3AaoW2u4XQJz1ya6fixv3pb3 github.com/therootcompany/golib/net/ipcohort v0.9.0/go.mod h1:Ljcnt2xOryVDGIVV5Kzt5hj2LhW4lBAWo5OeeVYU9ys= github.com/therootcompany/golib/net/iplist v0.9.1 h1:atyzk6RPSPP/E+2Y+Q1XzBs3GnDMXeCztgwqCfedZKs= github.com/therootcompany/golib/net/iplist v0.9.1/go.mod h1:8ifRSgp4ptijldClyh688NLom8EZre6E16JZ2AHCEMw= -github.com/therootcompany/golib/sync/cachable v0.1.0 h1:swCXtXB116jhSmla81HaXi/9cPsqFI+Oq/6OcSfdU5Q= -github.com/therootcompany/golib/sync/cachable v0.1.0/go.mod h1:l/NZdGiSbW5CkLlkkRa0yObkqak2sj/jQTXXqXwvCl0= +github.com/therootcompany/golib/sync/cacheable v0.1.0 h1:swCXtXB116jhSmla81HaXi/9cPsqFI+Oq/6OcSfdU5Q= +github.com/therootcompany/golib/sync/cacheable v0.1.0/go.mod h1:l/NZdGiSbW5CkLlkkRa0yObkqak2sj/jQTXXqXwvCl0= golang.org/x/mod v0.30.0 h1:fDEXFVZ/fmCKProc/yAXXUijritrDzahmwwefnjoPFk= golang.org/x/mod v0.30.0/go.mod h1:lAsf5O2EvJeSFMiBxXDki7sCgAxEUcZHXoXMKT4GJKc= golang.org/x/net v0.47.0 h1:Mx+4dIFzqraBXUugkia1OOvlD6LemFo1ALMHjrXDOhY= diff --git a/net/ippolicy/ipprefix.go b/net/ippolicy/ipprefix.go index dd0c9fe..d8fa93c 100644 --- a/net/ippolicy/ipprefix.go +++ b/net/ippolicy/ipprefix.go @@ -11,7 +11,7 @@ import ( "github.com/therootcompany/golib/net/gitshallow" "github.com/therootcompany/golib/net/ipcohort" - "github.com/therootcompany/golib/sync/cachable" + "github.com/therootcompany/golib/sync/cacheable" ) const ( @@ -31,7 +31,7 @@ type IPPrefixSet struct { lastErr atomic.Pointer[error] interval time.Duration RefreshTimeout time.Duration - refresh cachable.Refresh + refresh cacheable.Refresh } func EmptyIPPrefixSet() *IPPrefixSet { @@ -64,10 +64,10 @@ func NewIPPrefixSet(ctx context.Context, repoURL, dataPath string, files []strin } var ( - _ cachable.Cacheable[ipcohort.Cohort] = (*IPPrefixSet)(nil) - _ cachable.Mutable[ipcohort.Cohort] = (*IPPrefixSet)(nil) - _ cachable.Inspectable = (*IPPrefixSet)(nil) - _ cachable.Tickable = (*IPPrefixSet)(nil) + _ cacheable.Cacheable[ipcohort.Cohort] = (*IPPrefixSet)(nil) + _ cacheable.Mutable[ipcohort.Cohort] = (*IPPrefixSet)(nil) + _ cacheable.Inspectable = (*IPPrefixSet)(nil) + _ cacheable.Tickable = (*IPPrefixSet)(nil) ) func (ps *IPPrefixSet) Current() *ipcohort.Cohort { @@ -138,7 +138,7 @@ func (ps *IPPrefixSet) Clear() error { return ps.Set(nil) } -func (ps *IPPrefixSet) Status() cachable.Status { +func (ps *IPPrefixSet) Status() cacheable.Status { loadedAt := time.Time{} if t := ps.loadedAt.Load(); t != nil { loadedAt = *t @@ -147,7 +147,7 @@ func (ps *IPPrefixSet) Status() cachable.Status { if p := ps.lastErr.Load(); p != nil { lastErr = *p } - status := cachable.Status{LoadedAt: loadedAt, HasValue: ps.Current() != nil, Refreshing: ps.refresh.Running(), LastError: lastErr} + status := cacheable.Status{LoadedAt: loadedAt, HasValue: ps.Current() != nil, Refreshing: ps.refresh.Running(), LastError: lastErr} if !loadedAt.IsZero() { status.StaleAt = loadedAt.Add(ps.interval) } diff --git a/sync/cachable/go.mod b/sync/cachable/go.mod deleted file mode 100644 index e374a21..0000000 --- a/sync/cachable/go.mod +++ /dev/null @@ -1,3 +0,0 @@ -module github.com/therootcompany/golib/sync/cachable - -go 1.26.0 diff --git a/sync/cachable/cacheable.go b/sync/cacheable/cacheable.go similarity index 92% rename from sync/cachable/cacheable.go rename to sync/cacheable/cacheable.go index ffc648e..693e2db 100644 --- a/sync/cachable/cacheable.go +++ b/sync/cacheable/cacheable.go @@ -1,5 +1,5 @@ -// Package cachable defines contracts for lazily refreshed cached values. -package cachable +// Package cacheable defines contracts for lazily refreshed cached values. +package cacheable import ( "context" diff --git a/sync/cacheable/go.mod b/sync/cacheable/go.mod new file mode 100644 index 0000000..50aabcd --- /dev/null +++ b/sync/cacheable/go.mod @@ -0,0 +1,3 @@ +module github.com/therootcompany/golib/sync/cacheable + +go 1.26.0 diff --git a/sync/cachable/refresh.go b/sync/cacheable/refresh.go similarity index 99% rename from sync/cachable/refresh.go rename to sync/cacheable/refresh.go index b7847c3..5c87c21 100644 --- a/sync/cachable/refresh.go +++ b/sync/cacheable/refresh.go @@ -1,4 +1,4 @@ -package cachable +package cacheable import ( "context" diff --git a/sync/cachable/refresh_test.go b/sync/cacheable/refresh_test.go similarity index 99% rename from sync/cachable/refresh_test.go rename to sync/cacheable/refresh_test.go index ffdbaa6..8e9c6d3 100644 --- a/sync/cachable/refresh_test.go +++ b/sync/cacheable/refresh_test.go @@ -1,4 +1,4 @@ -package cachable +package cacheable import ( "context" diff --git a/sync/dataset/dataset.go b/sync/dataset/dataset.go index 966b3b4..e2364ad 100644 --- a/sync/dataset/dataset.go +++ b/sync/dataset/dataset.go @@ -22,7 +22,7 @@ import ( "sync/atomic" "time" - "github.com/therootcompany/golib/sync/cachable" + "github.com/therootcompany/golib/sync/cacheable" ) // Upstream reports whether an upstream source has changed since the last call. @@ -104,12 +104,12 @@ type Set struct { loadedAt atomic.Pointer[time.Time] start sync.Once cancel context.CancelFunc - refresh cachable.Refresh + refresh cacheable.Refresh generation atomic.Uint64 RefreshTimeout time.Duration // RefreshInterval gates how often Revalidate will start a refresh. Zero // means always due (freshness is delegated to the upstreams' own dedup - // windows). Set to a positive duration to match the other cachable + // windows). Set to a positive duration to match the other cacheable // implementations' time-based Due. RefreshInterval time.Duration } @@ -296,10 +296,10 @@ type View[T any] struct { } var ( - _ cachable.Cacheable[any] = (*View[any])(nil) - _ cachable.Mutable[any] = (*View[any])(nil) - _ cachable.Inspectable = (*View[any])(nil) - _ cachable.Tickable = (*View[any])(nil) + _ cacheable.Cacheable[any] = (*View[any])(nil) + _ cacheable.Mutable[any] = (*View[any])(nil) + _ cacheable.Inspectable = (*View[any])(nil) + _ cacheable.Tickable = (*View[any])(nil) ) // Current returns the current snapshot without blocking. It is nil before @@ -355,8 +355,8 @@ func (v *View[T]) Clear() error { // Status reports the view's published snapshot. StaleAt is populated from the // set's RefreshInterval (when set); with a zero interval StaleAt stays zero // because freshness is delegated to the upstreams. -func (v *View[T]) Status() cachable.Status { - status := cachable.Status{HasValue: v.Current() != nil, Refreshing: v.set.refresh.Running()} +func (v *View[T]) Status() cacheable.Status { + status := cacheable.Status{HasValue: v.Current() != nil, Refreshing: v.set.refresh.Running()} if loadedAt := v.loadedAt.Load(); loadedAt != nil { status.LoadedAt = *loadedAt if v.set.RefreshInterval > 0 { diff --git a/sync/dataset/go.mod b/sync/dataset/go.mod index 886ff23..cb0ed47 100644 --- a/sync/dataset/go.mod +++ b/sync/dataset/go.mod @@ -2,4 +2,4 @@ module github.com/therootcompany/golib/sync/dataset go 1.26.0 -require github.com/therootcompany/golib/sync/cachable v0.1.0 +require github.com/therootcompany/golib/sync/cacheable v0.1.0 diff --git a/sync/dataset/go.sum b/sync/dataset/go.sum index 1f7128a..a00d3b0 100644 --- a/sync/dataset/go.sum +++ b/sync/dataset/go.sum @@ -1,2 +1,2 @@ -github.com/therootcompany/golib/sync/cachable v0.1.0 h1:swCXtXB116jhSmla81HaXi/9cPsqFI+Oq/6OcSfdU5Q= -github.com/therootcompany/golib/sync/cachable v0.1.0/go.mod h1:l/NZdGiSbW5CkLlkkRa0yObkqak2sj/jQTXXqXwvCl0= +github.com/therootcompany/golib/sync/cacheable v0.1.0 h1:swCXtXB116jhSmla81HaXi/9cPsqFI+Oq/6OcSfdU5Q= +github.com/therootcompany/golib/sync/cacheable v0.1.0/go.mod h1:l/NZdGiSbW5CkLlkkRa0yObkqak2sj/jQTXXqXwvCl0=