chore: make reg cache expiry tunable

Mostly for the tests, opts:

- tuning.register_cache_expiration
- tuning.register_cache_cleanup
This commit is contained in:
Andrey Bobelev
2025-08-29 14:20:07 +02:00
committed by nblock
parent bd35fcf338
commit 022098fe4e
2 changed files with 16 additions and 2 deletions

View File

@@ -74,9 +74,19 @@ type State struct {
// NewState creates and initializes a new State instance, setting up the database,
// IP allocator, DERP map, policy manager, and loading existing users and nodes.
func NewState(cfg *types.Config) (*State, error) {
cacheExpiration := registerCacheExpiration
if cfg.Tuning.RegisterCacheExpiration != 0 {
cacheExpiration = cfg.Tuning.RegisterCacheExpiration
}
cacheCleanup := registerCacheCleanup
if cfg.Tuning.RegisterCacheCleanup != 0 {
cacheCleanup = cfg.Tuning.RegisterCacheCleanup
}
registrationCache := zcache.New[types.RegistrationID, types.RegisterNode](
registerCacheExpiration,
registerCacheCleanup,
cacheExpiration,
cacheCleanup,
)
db, err := hsdb.NewHeadscaleDatabase(