add configurable clear interval

This commit is contained in:
1e99 2024-10-30 00:25:53 +01:00
parent dfa37fc7fa
commit c8bbe24d4d
2 changed files with 12 additions and 10 deletions

View file

@ -6,8 +6,9 @@ import (
"time"
)
func NewRamStore() Store {
func NewRamStore(clearInterval time.Duration) Store {
store := &ram{
clearInterval: clearInterval,
passwords: make(map[string]entry),
lock: sync.Mutex{},
close: make(chan bool),
@ -18,6 +19,7 @@ func NewRamStore() Store {
}
type ram struct {
clearInterval time.Duration
passwords map[string]entry
lock sync.Mutex
close chan bool
@ -64,7 +66,7 @@ func (store *ram) Close() error {
}
func (store *ram) clearExpired() error {
ticker := time.NewTicker(20 * time.Second)
ticker := time.NewTicker(store.clearInterval)
defer ticker.Stop()
for {

View file

@ -30,10 +30,10 @@ func NewStore() (Store, error) {
switch storeType {
case "ram":
return NewRamStore(), nil
return NewRamStore(20 * time.Second), nil
default:
log.Printf("No PASSED_STORE_TYPE provided, defaulting to memory store.")
return NewRamStore(), nil
return NewRamStore(20 * time.Second), nil
}
}