33 lines
560 B
Go
33 lines
560 B
Go
package cache
|
|
|
|
import (
|
|
"time"
|
|
|
|
"github.com/Neur0toxine/wa-profile-api/internal/dto"
|
|
"github.com/jellydator/ttlcache/v2"
|
|
)
|
|
|
|
type profiles struct {
|
|
c *ttlcache.Cache
|
|
}
|
|
|
|
var Profiles *profiles
|
|
|
|
func init() {
|
|
c := ttlcache.NewCache()
|
|
c.SetTTL(time.Minute * 15)
|
|
Profiles = &profiles{c: c}
|
|
}
|
|
|
|
func (p *profiles) Get(phone string) (dto.WAProfile, bool) {
|
|
item, err := p.c.Get(phone)
|
|
if err != nil {
|
|
return dto.WAProfile{}, false
|
|
}
|
|
return item.(dto.WAProfile), true
|
|
}
|
|
|
|
func (p *profiles) Set(phone string, value dto.WAProfile) {
|
|
p.c.Set(phone, value)
|
|
}
|