eth-indexer/internal/cache/xmap.go

38 lines
491 B
Go
Raw Normal View History

2024-06-10 09:21:50 +02:00
package cache
import (
"github.com/puzpuzpuz/xsync/v3"
)
type Cache struct {
xmap *xsync.Map
}
func NewCache() *Cache {
return &Cache{
xmap: xsync.NewMap(),
}
}
func (c *Cache) Purge() error {
c.xmap.Clear()
return nil
}
func (c *Cache) Exists(key string) bool {
_, ok := c.xmap.Load(key)
return ok
}
func (c *Cache) Add(key string) {
c.xmap.Store(key, nil)
}
func (c *Cache) Remove(key string) {
c.xmap.Delete(key)
}
func (c *Cache) Size() int {
return c.xmap.Size()
}