Skip to content

Commit

Permalink
Merge pull request #46 from Ritchie6/memo3
Browse files Browse the repository at this point in the history
Implemented the Close() method- Fixed issue #17
  • Loading branch information
rtb-12 authored Jan 14, 2025
2 parents 7194b61 + 8ada4aa commit 34d0936
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions memoria.go
Original file line number Diff line number Diff line change
Expand Up @@ -436,3 +436,18 @@ func (m *Memoria) BulkWrite(pairs map[string][]byte, numWorkers int) []WriteResu
return results

}

// Implementing the Close() method:

func (m *Memoria) Close() error { // Here, the Close() method only clears the in-memory cache
m.mu.Lock()
defer m.mu.Unlock()

// Clearing the cache within the memory:
for key := range m.cache {
delete(m.cache, key) // To delete the key from cache map
}
m.cacheSize = 0

return nil
}

0 comments on commit 34d0936

Please sign in to comment.