commit 03bf7bfc1b662c7889be9b25a1ca088e04be857f
parent cb22240f1cb9f4d0c120433805dc4dc462566fa7
Author: lash <dev@holbrook.no>
Date: Wed, 28 May 2025 13:41:50 +0100
Add full memory reset method
Diffstat:
4 files changed, 17 insertions(+), 8 deletions(-)
diff --git a/cache/cache.go b/cache/cache.go
@@ -23,10 +23,8 @@ type Cache struct {
// NewCache creates a new ready-to-use Cache object
func NewCache() *Cache {
- ca := &Cache{
- Cache: []map[string]string{make(map[string]string)},
- Sizes: make(map[string]uint16),
- }
+ ca := &Cache{}
+ ca.ResetFull()
return ca
}
@@ -130,6 +128,14 @@ func (ca *Cache) Get(key string) (string, error) {
}
// Reset implements the Memory interface.
+func (ca *Cache) ResetFull() {
+ ca.Cache = []map[string]string{make(map[string]string)}
+ ca.Sizes = make(map[string]uint16)
+ ca.CacheUseSize = 0
+ return
+}
+
+// Reset implements the Memory interface.
func (ca *Cache) Reset() {
var v string
if len(ca.Cache) == 0 {
diff --git a/cache/cache_test.go b/cache/cache_test.go
@@ -158,7 +158,7 @@ func TestCacheReset(t *testing.T) {
}
ca.Reset()
if ca.CacheUseSize != 3 {
- t.Errorf("expected cache use size 0, got %v", ca.CacheUseSize)
+ t.Errorf("expected cache use size 3, got %v", ca.CacheUseSize)
}
}
diff --git a/cache/memory.go b/cache/memory.go
@@ -34,6 +34,8 @@ type Memory interface {
Pop() error
// Reset flushes all state contents below the top level.
Reset()
+ // Reset flushes all state contents including the top level.
+ ResetFull()
// Levels returns the current number of levels.
Levels() uint32
// Keys returns all storage keys for the given level.
diff --git a/engine/db.go b/engine/db.go
@@ -637,10 +637,11 @@ func (en *DefaultEngine) reset(ctx context.Context) (bool, error) {
if err != nil {
return false, err
}
- en.ca.Pop()
}
- if (en.cfg.ResetRoot) {
- en.ca.Pop()
+ if en.cfg.ResetRoot {
+ en.ca.ResetFull()
+ } else {
+ en.ca.Reset()
}
en.st.Restart()
en.st.ResetFlag(state.FLAG_TERMINATE)