refactor: restructure project
This commit is contained in:
parent
1bde2041e1
commit
8215e1f13a
21 changed files with 850 additions and 269 deletions
30
internal/cache/cache.go
vendored
Normal file
30
internal/cache/cache.go
vendored
Normal file
|
@ -0,0 +1,30 @@
|
|||
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
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue