Skip to content

Commit

Permalink
Implemented the Close() method
Browse files Browse the repository at this point in the history
  • Loading branch information
Ritchie6 committed Dec 20, 2024
1 parent e691773 commit 8ada4aa
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 8ada4aa

Please sign in to comment.