summaryrefslogtreecommitdiff
path: root/plugins/memory
diff options
context:
space:
mode:
authorValery Piashchynski <[email protected]>2021-06-24 15:31:15 +0300
committerValery Piashchynski <[email protected]>2021-06-24 15:31:15 +0300
commitfdff0ffe41b45d0e919eccc683104987898a4faf (patch)
tree79b242b1af7d283eedfb0ac124e48c5fa47ef461 /plugins/memory
parentce53a8e149b76f15e8a5dd88ac3b953798d57e8b (diff)
- Add Clear method to the storages
Signed-off-by: Valery Piashchynski <[email protected]>
Diffstat (limited to 'plugins/memory')
-rw-r--r--plugins/memory/kv.go16
1 files changed, 15 insertions, 1 deletions
diff --git a/plugins/memory/kv.go b/plugins/memory/kv.go
index 1cf031d1..83f6630e 100644
--- a/plugins/memory/kv.go
+++ b/plugins/memory/kv.go
@@ -13,7 +13,8 @@ import (
)
type Driver struct {
- heap sync.Map
+ clearMu sync.RWMutex
+ heap sync.Map
// stop is used to stop keys GC and close boltdb connection
stop chan struct{}
log logger.Logger
@@ -203,6 +204,14 @@ func (s *Driver) Delete(keys ...string) error {
return nil
}
+func (s *Driver) Clear() error {
+ s.clearMu.Lock()
+ s.heap = sync.Map{}
+ s.clearMu.Unlock()
+
+ return nil
+}
+
// ================================== PRIVATE ======================================
func (s *Driver) gc() {
@@ -213,6 +222,9 @@ func (s *Driver) gc() {
ticker.Stop()
return
case now := <-ticker.C:
+ // mutes needed to clear the map
+ s.clearMu.Lock()
+
// check every second
s.heap.Range(func(key, value interface{}) bool {
v := value.(*kvv1.Item)
@@ -231,6 +243,8 @@ func (s *Driver) gc() {
}
return true
})
+
+ s.clearMu.Unlock()
}
}
}