diff --git a/gache.go b/gache.go index d52ad9c..2336acd 100644 --- a/gache.go +++ b/gache.go @@ -289,8 +289,12 @@ func Set(key string, val interface{}) { // Delete deletes value from Gache using key func (g *gache) Delete(key string) { - atomic.StoreUint64(&g.l, atomic.LoadUint64(&g.l)-1) - g.shards[xxhash.Sum64(*(*[]byte)(unsafe.Pointer(&key)))&mask].Delete(key) + for { + if v := atomic.LoadUint64((*uint64)(&g.l)); atomic.CompareAndSwapUint64((*uint64)(&g.l), v, v-1) { + g.shards[xxhash.Sum64(*(*[]byte)(unsafe.Pointer(&key)))&mask].Delete(key) + return + } + } } // Delete deletes value from Gache using key diff --git a/go.mod b/go.mod index b6aaa2f..b888fd8 100644 --- a/go.mod +++ b/go.mod @@ -12,7 +12,6 @@ require ( github.com/kpango/fastime v1.0.8 github.com/kpango/glg v1.3.0 github.com/patrickmn/go-cache v2.1.0+incompatible - github.com/pierrec/lz4 v2.0.5+incompatible golang.org/x/sync v0.0.0-20190227155943-e225da77a7e6 google.golang.org/appengine v1.5.0 // indirect ) diff --git a/go.sum b/go.sum index d82778d..0e9eb78 100644 --- a/go.sum +++ b/go.sum @@ -29,8 +29,6 @@ github.com/kpango/glg v1.3.0 h1:77BWdR0kKkFloM2eSAr0A7lWvUyAIlOhj4LV5n2hrB8= github.com/kpango/glg v1.3.0/go.mod h1:7zzaAoMqvngad+sagWLjr00EQMJaqyGONdg0WYBAO3M= github.com/patrickmn/go-cache v2.1.0+incompatible h1:HRMgzkcYKYpi3C8ajMPV8OFXaaRUnok+kx1WdO15EQc= github.com/patrickmn/go-cache v2.1.0+incompatible/go.mod h1:3Qf8kWWT7OJRJbdiICTKqZju1ZixQ/KpMGzzAfe6+WQ= -github.com/pierrec/lz4 v2.0.5+incompatible h1:2xWsjqPFWcplujydGg4WmhC/6fZqK42wMM8aXeqhl0I= -github.com/pierrec/lz4 v2.0.5+incompatible/go.mod h1:pdkljMzZIN41W+lC3N2tnIh5sFi+IEE17M5jbnwPHcY= github.com/spaolacci/murmur3 v0.0.0-20180118202830-f09979ecbc72/go.mod h1:JwIasOWyU6f++ZhiEuf87xNszmSA2myDM2Kzu9HwQUA= github.com/vmihailenco/msgpack v4.0.1+incompatible h1:RMF1enSPeKTlXrXdOcqjFUElywVZjjC6pqse21bKbEU= github.com/vmihailenco/msgpack v4.0.1+incompatible/go.mod h1:fy3FlTQTDXWkZ7Bh6AcGMlsjHatGryHQYUTf1ShIgkk=