mirror of
https://github.com/therootcompany/golib.git
synced 2026-11-04 06:55:00 +00:00
refactor(sync): rename cacheable package
This commit is contained in:
parent
7990917414
commit
db1d4c55a9
@ -14,7 +14,7 @@ require (
|
|||||||
github.com/oschwald/geoip2-golang v1.13.0 // indirect
|
github.com/oschwald/geoip2-golang v1.13.0 // indirect
|
||||||
github.com/oschwald/maxminddb-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/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/sync v0.20.0 // indirect
|
||||||
golang.org/x/sys v0.45.0 // indirect
|
golang.org/x/sys v0.45.0 // indirect
|
||||||
)
|
)
|
||||||
|
|||||||
@ -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/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 h1:j3AaoW2u4XQJz1ya6fixv3pb3KgxIpZV8t0082/kS3E=
|
||||||
github.com/therootcompany/golib/net/ipcohort v0.9.0/go.mod h1:Ljcnt2xOryVDGIVV5Kzt5hj2LhW4lBAWo5OeeVYU9ys=
|
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/cacheable 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/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 h1:Gerq315Ld1PyfD+6EmTDxSEAOg6s0kDchL2oo/jAQZ0=
|
||||||
github.com/therootcompany/golib/sync/dataset v0.6.0/go.mod h1:ktn0ppeIpNvgNLFYFuD9W6hGEQfwaIEcE8TV048+Y9M=
|
github.com/therootcompany/golib/sync/dataset v0.6.0/go.mod h1:ktn0ppeIpNvgNLFYFuD9W6hGEQfwaIEcE8TV048+Y9M=
|
||||||
golang.org/x/sync v0.20.0 h1:e0PTpb7pjO8GAtTs2dQ6jYa5BWYlMuX047Dco/pItO4=
|
golang.org/x/sync v0.20.0 h1:e0PTpb7pjO8GAtTs2dQ6jYa5BWYlMuX047Dco/pItO4=
|
||||||
|
|||||||
@ -21,7 +21,7 @@ require (
|
|||||||
github.com/therootcompany/golib/net/ipcohort v0.9.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/net/iplist v0.9.1 // indirect
|
||||||
github.com/therootcompany/golib/net/ippolicy 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/mod v0.30.0 // indirect
|
||||||
golang.org/x/net v0.47.0 // indirect
|
golang.org/x/net v0.47.0 // indirect
|
||||||
golang.org/x/sync v0.20.0 // indirect
|
golang.org/x/sync v0.20.0 // indirect
|
||||||
|
|||||||
@ -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/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 h1:szAPNGFaJyD44MRSQ3r+AXOVdRVaoS8rMob44V8UbUk=
|
||||||
github.com/therootcompany/golib/net/ippolicy v0.9.1/go.mod h1:3FpLflMoNLpHlE2XgHaXTekFHgg3BBRFqkOm+9hvosQ=
|
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/cacheable 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/go.mod h1:l/NZdGiSbW5CkLlkkRa0yObkqak2sj/jQTXXqXwvCl0=
|
||||||
golang.org/x/mod v0.30.0 h1:fDEXFVZ/fmCKProc/yAXXUijritrDzahmwwefnjoPFk=
|
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/mod v0.30.0/go.mod h1:lAsf5O2EvJeSFMiBxXDki7sCgAxEUcZHXoXMKT4GJKc=
|
||||||
golang.org/x/net v0.47.0 h1:Mx+4dIFzqraBXUugkia1OOvlD6LemFo1ALMHjrXDOhY=
|
golang.org/x/net v0.47.0 h1:Mx+4dIFzqraBXUugkia1OOvlD6LemFo1ALMHjrXDOhY=
|
||||||
|
|||||||
@ -19,7 +19,7 @@ require (
|
|||||||
github.com/therootcompany/golib/net/httpcache v0.6.0 // indirect
|
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/ipcohort v0.9.0 // indirect
|
||||||
github.com/therootcompany/golib/net/iplist v0.9.1 // 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/mod v0.30.0 // indirect
|
||||||
golang.org/x/net v0.47.0 // indirect
|
golang.org/x/net v0.47.0 // indirect
|
||||||
golang.org/x/sync v0.20.0 // indirect
|
golang.org/x/sync v0.20.0 // indirect
|
||||||
|
|||||||
@ -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/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 h1:szAPNGFaJyD44MRSQ3r+AXOVdRVaoS8rMob44V8UbUk=
|
||||||
github.com/therootcompany/golib/net/ippolicy v0.9.1/go.mod h1:3FpLflMoNLpHlE2XgHaXTekFHgg3BBRFqkOm+9hvosQ=
|
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/cacheable 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/go.mod h1:l/NZdGiSbW5CkLlkkRa0yObkqak2sj/jQTXXqXwvCl0=
|
||||||
golang.org/x/mod v0.30.0 h1:fDEXFVZ/fmCKProc/yAXXUijritrDzahmwwefnjoPFk=
|
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/mod v0.30.0/go.mod h1:lAsf5O2EvJeSFMiBxXDki7sCgAxEUcZHXoXMKT4GJKc=
|
||||||
golang.org/x/net v0.47.0 h1:Mx+4dIFzqraBXUugkia1OOvlD6LemFo1ALMHjrXDOhY=
|
golang.org/x/net v0.47.0 h1:Mx+4dIFzqraBXUugkia1OOvlD6LemFo1ALMHjrXDOhY=
|
||||||
|
|||||||
@ -13,7 +13,7 @@ import (
|
|||||||
|
|
||||||
"github.com/therootcompany/golib/https"
|
"github.com/therootcompany/golib/https"
|
||||||
"github.com/therootcompany/golib/net/httpcache"
|
"github.com/therootcompany/golib/net/httpcache"
|
||||||
"github.com/therootcompany/golib/sync/cachable"
|
"github.com/therootcompany/golib/sync/cacheable"
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
@ -43,7 +43,7 @@ type GeoIPDB struct {
|
|||||||
cancel context.CancelFunc
|
cancel context.CancelFunc
|
||||||
loadedAt atomic.Pointer[time.Time]
|
loadedAt atomic.Pointer[time.Time]
|
||||||
lastErr atomic.Pointer[error]
|
lastErr atomic.Pointer[error]
|
||||||
refresh cachable.Refresh
|
refresh cacheable.Refresh
|
||||||
local bool
|
local bool
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -105,10 +105,10 @@ func (f *GeoIPDB) ready() error {
|
|||||||
|
|
||||||
// Fetch downloads all configured editions and reports whether any changed.
|
// Fetch downloads all configured editions and reports whether any changed.
|
||||||
var (
|
var (
|
||||||
_ cachable.Cacheable[Databases] = (*GeoIPDB)(nil)
|
_ cacheable.Cacheable[Databases] = (*GeoIPDB)(nil)
|
||||||
_ cachable.Mutable[Databases] = (*GeoIPDB)(nil)
|
_ cacheable.Mutable[Databases] = (*GeoIPDB)(nil)
|
||||||
_ cachable.Inspectable = (*GeoIPDB)(nil)
|
_ cacheable.Inspectable = (*GeoIPDB)(nil)
|
||||||
_ cachable.Tickable = (*GeoIPDB)(nil)
|
_ cacheable.Tickable = (*GeoIPDB)(nil)
|
||||||
)
|
)
|
||||||
|
|
||||||
// Current returns the newest completed City+ASN snapshot without blocking.
|
// Current returns the newest completed City+ASN snapshot without blocking.
|
||||||
@ -195,7 +195,7 @@ func (f *GeoIPDB) Clear() error {
|
|||||||
return f.Set(nil)
|
return f.Set(nil)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (f *GeoIPDB) Status() cachable.Status {
|
func (f *GeoIPDB) Status() cacheable.Status {
|
||||||
loadedAt := time.Time{}
|
loadedAt := time.Time{}
|
||||||
if t := f.loadedAt.Load(); t != nil {
|
if t := f.loadedAt.Load(); t != nil {
|
||||||
loadedAt = *t
|
loadedAt = *t
|
||||||
@ -204,7 +204,7 @@ func (f *GeoIPDB) Status() cachable.Status {
|
|||||||
if p := f.lastErr.Load(); p != nil {
|
if p := f.lastErr.Load(); p != nil {
|
||||||
lastErr = *p
|
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 {
|
if !loadedAt.IsZero() && f.maxAge > 0 {
|
||||||
status.StaleAt = loadedAt.Add(f.maxAge)
|
status.StaleAt = loadedAt.Add(f.maxAge)
|
||||||
}
|
}
|
||||||
|
|||||||
@ -6,7 +6,7 @@ require (
|
|||||||
github.com/oschwald/geoip2-golang v1.13.0
|
github.com/oschwald/geoip2-golang v1.13.0
|
||||||
github.com/therootcompany/golib/https v0.9.0
|
github.com/therootcompany/golib/https v0.9.0
|
||||||
github.com/therootcompany/golib/net/httpcache v0.6.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 (
|
require (
|
||||||
|
|||||||
@ -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/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 h1:qFBnSs6rZrtUQ+fweP4bHF2FQd/Syvs7mRN5nO5YtkY=
|
||||||
github.com/therootcompany/golib/net/httpcache v0.6.0/go.mod h1:mKSQJWpGSCDBzWkTCwT7dO1SCVCsFmdkRgKr39fNS1U=
|
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/cacheable 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/go.mod h1:l/NZdGiSbW5CkLlkkRa0yObkqak2sj/jQTXXqXwvCl0=
|
||||||
golang.org/x/sync v0.20.0 h1:e0PTpb7pjO8GAtTs2dQ6jYa5BWYlMuX047Dco/pItO4=
|
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/sync v0.20.0/go.mod h1:9xrNwdLfx4jkKbNva9FpL6vEN7evnE43NNNJQ2LF3+0=
|
||||||
golang.org/x/sys v0.45.0 h1:dO4czNzziLiiXplLQgBCEpCvXQ3dnkn0SdaZSYdQ+FY=
|
golang.org/x/sys v0.45.0 h1:dO4czNzziLiiXplLQgBCEpCvXQ3dnkn0SdaZSYdQ+FY=
|
||||||
|
|||||||
@ -6,7 +6,7 @@ require (
|
|||||||
github.com/therootcompany/golib/https v0.9.0
|
github.com/therootcompany/golib/https v0.9.0
|
||||||
github.com/therootcompany/golib/io/transform/gsheet2csv v1.1.0
|
github.com/therootcompany/golib/io/transform/gsheet2csv v1.1.0
|
||||||
github.com/therootcompany/golib/net/httpcache v0.6.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
|
require golang.org/x/sync v0.20.0 // indirect
|
||||||
|
|||||||
@ -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/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 h1:qFBnSs6rZrtUQ+fweP4bHF2FQd/Syvs7mRN5nO5YtkY=
|
||||||
github.com/therootcompany/golib/net/httpcache v0.6.0/go.mod h1:mKSQJWpGSCDBzWkTCwT7dO1SCVCsFmdkRgKr39fNS1U=
|
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/cacheable 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/go.mod h1:l/NZdGiSbW5CkLlkkRa0yObkqak2sj/jQTXXqXwvCl0=
|
||||||
golang.org/x/sync v0.20.0 h1:e0PTpb7pjO8GAtTs2dQ6jYa5BWYlMuX047Dco/pItO4=
|
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/sync v0.20.0/go.mod h1:9xrNwdLfx4jkKbNva9FpL6vEN7evnE43NNNJQ2LF3+0=
|
||||||
|
|||||||
@ -10,7 +10,7 @@ import (
|
|||||||
"sync/atomic"
|
"sync/atomic"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/therootcompany/golib/sync/cachable"
|
"github.com/therootcompany/golib/sync/cacheable"
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
@ -36,14 +36,14 @@ type IPList struct {
|
|||||||
generation atomic.Uint64
|
generation atomic.Uint64
|
||||||
loadedAt atomic.Pointer[time.Time]
|
loadedAt atomic.Pointer[time.Time]
|
||||||
lastErr atomic.Pointer[error]
|
lastErr atomic.Pointer[error]
|
||||||
refresh cachable.Refresh
|
refresh cacheable.Refresh
|
||||||
}
|
}
|
||||||
|
|
||||||
var (
|
var (
|
||||||
_ cachable.Cacheable[[]string] = (*IPList)(nil)
|
_ cacheable.Cacheable[[]string] = (*IPList)(nil)
|
||||||
_ cachable.Mutable[[]string] = (*IPList)(nil)
|
_ cacheable.Mutable[[]string] = (*IPList)(nil)
|
||||||
_ cachable.Inspectable = (*IPList)(nil)
|
_ cacheable.Inspectable = (*IPList)(nil)
|
||||||
_ cachable.Tickable = (*IPList)(nil)
|
_ cacheable.Tickable = (*IPList)(nil)
|
||||||
)
|
)
|
||||||
|
|
||||||
func NewIPList(ctx context.Context, config IPListConfig) (*IPList, error) {
|
func NewIPList(ctx context.Context, config IPListConfig) (*IPList, error) {
|
||||||
@ -137,7 +137,7 @@ func (s *IPList) Clear() error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *IPList) Status() cachable.Status {
|
func (s *IPList) Status() cacheable.Status {
|
||||||
loadedAt := time.Time{}
|
loadedAt := time.Time{}
|
||||||
if t := s.loadedAt.Load(); t != nil {
|
if t := s.loadedAt.Load(); t != nil {
|
||||||
loadedAt = *t
|
loadedAt = *t
|
||||||
@ -146,7 +146,7 @@ func (s *IPList) Status() cachable.Status {
|
|||||||
if p := s.lastErr.Load(); p != nil {
|
if p := s.lastErr.Load(); p != nil {
|
||||||
lastErr = *p
|
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() {
|
if !loadedAt.IsZero() {
|
||||||
status.StaleAt = loadedAt.Add(s.config.RefreshInterval)
|
status.StaleAt = loadedAt.Add(s.config.RefreshInterval)
|
||||||
}
|
}
|
||||||
|
|||||||
@ -11,7 +11,7 @@ import (
|
|||||||
|
|
||||||
"github.com/therootcompany/golib/net/dnsresolver"
|
"github.com/therootcompany/golib/net/dnsresolver"
|
||||||
"github.com/therootcompany/golib/net/ipcohort"
|
"github.com/therootcompany/golib/net/ipcohort"
|
||||||
"github.com/therootcompany/golib/sync/cachable"
|
"github.com/therootcompany/golib/sync/cacheable"
|
||||||
)
|
)
|
||||||
|
|
||||||
const DefaultDomainSetRefreshInterval = 5 * time.Minute
|
const DefaultDomainSetRefreshInterval = 5 * time.Minute
|
||||||
@ -95,7 +95,12 @@ func (ds *DomainSet) Replace(staticPrefixes, domains []string) {
|
|||||||
ds.rebuildCohort()
|
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.
|
// Start starts at most one optional background DNS refresh ticker.
|
||||||
func (ds *DomainSet) Start(ctx context.Context, interval time.Duration) {
|
func (ds *DomainSet) Start(ctx context.Context, interval time.Duration) {
|
||||||
|
|||||||
@ -7,7 +7,7 @@ require (
|
|||||||
github.com/therootcompany/golib/net/gitshallow v0.10.0
|
github.com/therootcompany/golib/net/gitshallow v0.10.0
|
||||||
github.com/therootcompany/golib/net/ipcohort v0.9.0
|
github.com/therootcompany/golib/net/ipcohort v0.9.0
|
||||||
github.com/therootcompany/golib/net/iplist v0.9.1
|
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 (
|
require (
|
||||||
|
|||||||
@ -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/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 h1:atyzk6RPSPP/E+2Y+Q1XzBs3GnDMXeCztgwqCfedZKs=
|
||||||
github.com/therootcompany/golib/net/iplist v0.9.1/go.mod h1:8ifRSgp4ptijldClyh688NLom8EZre6E16JZ2AHCEMw=
|
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/cacheable 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/go.mod h1:l/NZdGiSbW5CkLlkkRa0yObkqak2sj/jQTXXqXwvCl0=
|
||||||
golang.org/x/mod v0.30.0 h1:fDEXFVZ/fmCKProc/yAXXUijritrDzahmwwefnjoPFk=
|
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/mod v0.30.0/go.mod h1:lAsf5O2EvJeSFMiBxXDki7sCgAxEUcZHXoXMKT4GJKc=
|
||||||
golang.org/x/net v0.47.0 h1:Mx+4dIFzqraBXUugkia1OOvlD6LemFo1ALMHjrXDOhY=
|
golang.org/x/net v0.47.0 h1:Mx+4dIFzqraBXUugkia1OOvlD6LemFo1ALMHjrXDOhY=
|
||||||
|
|||||||
@ -11,7 +11,7 @@ import (
|
|||||||
|
|
||||||
"github.com/therootcompany/golib/net/gitshallow"
|
"github.com/therootcompany/golib/net/gitshallow"
|
||||||
"github.com/therootcompany/golib/net/ipcohort"
|
"github.com/therootcompany/golib/net/ipcohort"
|
||||||
"github.com/therootcompany/golib/sync/cachable"
|
"github.com/therootcompany/golib/sync/cacheable"
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
@ -31,7 +31,7 @@ type IPPrefixSet struct {
|
|||||||
lastErr atomic.Pointer[error]
|
lastErr atomic.Pointer[error]
|
||||||
interval time.Duration
|
interval time.Duration
|
||||||
RefreshTimeout time.Duration
|
RefreshTimeout time.Duration
|
||||||
refresh cachable.Refresh
|
refresh cacheable.Refresh
|
||||||
}
|
}
|
||||||
|
|
||||||
func EmptyIPPrefixSet() *IPPrefixSet {
|
func EmptyIPPrefixSet() *IPPrefixSet {
|
||||||
@ -64,10 +64,10 @@ func NewIPPrefixSet(ctx context.Context, repoURL, dataPath string, files []strin
|
|||||||
}
|
}
|
||||||
|
|
||||||
var (
|
var (
|
||||||
_ cachable.Cacheable[ipcohort.Cohort] = (*IPPrefixSet)(nil)
|
_ cacheable.Cacheable[ipcohort.Cohort] = (*IPPrefixSet)(nil)
|
||||||
_ cachable.Mutable[ipcohort.Cohort] = (*IPPrefixSet)(nil)
|
_ cacheable.Mutable[ipcohort.Cohort] = (*IPPrefixSet)(nil)
|
||||||
_ cachable.Inspectable = (*IPPrefixSet)(nil)
|
_ cacheable.Inspectable = (*IPPrefixSet)(nil)
|
||||||
_ cachable.Tickable = (*IPPrefixSet)(nil)
|
_ cacheable.Tickable = (*IPPrefixSet)(nil)
|
||||||
)
|
)
|
||||||
|
|
||||||
func (ps *IPPrefixSet) Current() *ipcohort.Cohort {
|
func (ps *IPPrefixSet) Current() *ipcohort.Cohort {
|
||||||
@ -138,7 +138,7 @@ func (ps *IPPrefixSet) Clear() error {
|
|||||||
return ps.Set(nil)
|
return ps.Set(nil)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (ps *IPPrefixSet) Status() cachable.Status {
|
func (ps *IPPrefixSet) Status() cacheable.Status {
|
||||||
loadedAt := time.Time{}
|
loadedAt := time.Time{}
|
||||||
if t := ps.loadedAt.Load(); t != nil {
|
if t := ps.loadedAt.Load(); t != nil {
|
||||||
loadedAt = *t
|
loadedAt = *t
|
||||||
@ -147,7 +147,7 @@ func (ps *IPPrefixSet) Status() cachable.Status {
|
|||||||
if p := ps.lastErr.Load(); p != nil {
|
if p := ps.lastErr.Load(); p != nil {
|
||||||
lastErr = *p
|
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() {
|
if !loadedAt.IsZero() {
|
||||||
status.StaleAt = loadedAt.Add(ps.interval)
|
status.StaleAt = loadedAt.Add(ps.interval)
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,3 +0,0 @@
|
|||||||
module github.com/therootcompany/golib/sync/cachable
|
|
||||||
|
|
||||||
go 1.26.0
|
|
||||||
@ -1,5 +1,5 @@
|
|||||||
// Package cachable defines contracts for lazily refreshed cached values.
|
// Package cacheable defines contracts for lazily refreshed cached values.
|
||||||
package cachable
|
package cacheable
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
3
sync/cacheable/go.mod
Normal file
3
sync/cacheable/go.mod
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
module github.com/therootcompany/golib/sync/cacheable
|
||||||
|
|
||||||
|
go 1.26.0
|
||||||
@ -1,4 +1,4 @@
|
|||||||
package cachable
|
package cacheable
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
@ -1,4 +1,4 @@
|
|||||||
package cachable
|
package cacheable
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
@ -22,7 +22,7 @@ import (
|
|||||||
"sync/atomic"
|
"sync/atomic"
|
||||||
"time"
|
"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.
|
// Upstream reports whether an upstream source has changed since the last call.
|
||||||
@ -104,12 +104,12 @@ type Set struct {
|
|||||||
loadedAt atomic.Pointer[time.Time]
|
loadedAt atomic.Pointer[time.Time]
|
||||||
start sync.Once
|
start sync.Once
|
||||||
cancel context.CancelFunc
|
cancel context.CancelFunc
|
||||||
refresh cachable.Refresh
|
refresh cacheable.Refresh
|
||||||
generation atomic.Uint64
|
generation atomic.Uint64
|
||||||
RefreshTimeout time.Duration
|
RefreshTimeout time.Duration
|
||||||
// RefreshInterval gates how often Revalidate will start a refresh. Zero
|
// RefreshInterval gates how often Revalidate will start a refresh. Zero
|
||||||
// means always due (freshness is delegated to the upstreams' own dedup
|
// 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.
|
// implementations' time-based Due.
|
||||||
RefreshInterval time.Duration
|
RefreshInterval time.Duration
|
||||||
}
|
}
|
||||||
@ -296,10 +296,10 @@ type View[T any] struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
var (
|
var (
|
||||||
_ cachable.Cacheable[any] = (*View[any])(nil)
|
_ cacheable.Cacheable[any] = (*View[any])(nil)
|
||||||
_ cachable.Mutable[any] = (*View[any])(nil)
|
_ cacheable.Mutable[any] = (*View[any])(nil)
|
||||||
_ cachable.Inspectable = (*View[any])(nil)
|
_ cacheable.Inspectable = (*View[any])(nil)
|
||||||
_ cachable.Tickable = (*View[any])(nil)
|
_ cacheable.Tickable = (*View[any])(nil)
|
||||||
)
|
)
|
||||||
|
|
||||||
// Current returns the current snapshot without blocking. It is nil before
|
// 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
|
// Status reports the view's published snapshot. StaleAt is populated from the
|
||||||
// set's RefreshInterval (when set); with a zero interval StaleAt stays zero
|
// set's RefreshInterval (when set); with a zero interval StaleAt stays zero
|
||||||
// because freshness is delegated to the upstreams.
|
// because freshness is delegated to the upstreams.
|
||||||
func (v *View[T]) Status() cachable.Status {
|
func (v *View[T]) Status() cacheable.Status {
|
||||||
status := cachable.Status{HasValue: v.Current() != nil, Refreshing: v.set.refresh.Running()}
|
status := cacheable.Status{HasValue: v.Current() != nil, Refreshing: v.set.refresh.Running()}
|
||||||
if loadedAt := v.loadedAt.Load(); loadedAt != nil {
|
if loadedAt := v.loadedAt.Load(); loadedAt != nil {
|
||||||
status.LoadedAt = *loadedAt
|
status.LoadedAt = *loadedAt
|
||||||
if v.set.RefreshInterval > 0 {
|
if v.set.RefreshInterval > 0 {
|
||||||
|
|||||||
@ -2,4 +2,4 @@ module github.com/therootcompany/golib/sync/dataset
|
|||||||
|
|
||||||
go 1.26.0
|
go 1.26.0
|
||||||
|
|
||||||
require github.com/therootcompany/golib/sync/cachable v0.1.0
|
require github.com/therootcompany/golib/sync/cacheable v0.1.0
|
||||||
|
|||||||
@ -1,2 +1,2 @@
|
|||||||
github.com/therootcompany/golib/sync/cachable v0.1.0 h1:swCXtXB116jhSmla81HaXi/9cPsqFI+Oq/6OcSfdU5Q=
|
github.com/therootcompany/golib/sync/cacheable 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/go.mod h1:l/NZdGiSbW5CkLlkkRa0yObkqak2sj/jQTXXqXwvCl0=
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user