mirror of
https://github.com/grassrootseconomics/eth-tracker.git
synced 2026-05-18 10:45:21 +02:00
release: v1.0.0-rc
This commit is contained in:
36
internal/cache/xmap.go
vendored
Normal file
36
internal/cache/xmap.go
vendored
Normal file
@@ -0,0 +1,36 @@
|
||||
package cache
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/puzpuzpuz/xsync/v3"
|
||||
)
|
||||
|
||||
type mapCache struct {
|
||||
xmap *xsync.Map
|
||||
}
|
||||
|
||||
func NewMapCache() Cache {
|
||||
return &mapCache{
|
||||
xmap: xsync.NewMap(),
|
||||
}
|
||||
}
|
||||
|
||||
func (c *mapCache) Add(_ context.Context, key string) error {
|
||||
c.xmap.Store(key, true)
|
||||
return nil
|
||||
}
|
||||
|
||||
func (c *mapCache) Remove(_ context.Context, key string) error {
|
||||
c.xmap.Delete(key)
|
||||
return nil
|
||||
}
|
||||
|
||||
func (c *mapCache) Exists(_ context.Context, key string) (bool, error) {
|
||||
_, ok := c.xmap.Load(key)
|
||||
return ok, nil
|
||||
}
|
||||
|
||||
func (c *mapCache) Size(_ context.Context) (int64, error) {
|
||||
return int64(c.xmap.Size()), nil
|
||||
}
|
||||
Reference in New Issue
Block a user