country-geo-locations/internal/cache/cache.go
Tom Neuber 8215e1f13a
All checks were successful
ci/woodpecker/push/lint Pipeline was successful
ci/woodpecker/push/test Pipeline was successful
ci/woodpecker/push/build Pipeline was successful
ci/woodpecker/push/deploy Pipeline was successful
refactor: restructure project
2024-11-26 13:35:54 +01:00

30 lines
431 B
Go

package cache
import (
"sync"
"time"
)
type Cache struct {
ttl time.Duration
store sync.Map
}
func NewCache(ttl time.Duration) *Cache {
return &Cache{
ttl: ttl,
}
}
func (c *Cache) Set(key, value uint) {
c.store.Store(key, value)
time.AfterFunc(c.ttl, func() {
c.store.Delete(key)
})
}
func (c *Cache) Get(key uint) (uint, bool) {
output, _ := c.store.Load(key)
value, ok := output.(uint)
return value, ok
}