From 8ada4aa3ce0fb522510371f711a09f0b9c0aa674 Mon Sep 17 00:00:00 2001 From: Ritchie6 <191115765+Ritchie6@users.noreply.github.com> Date: Fri, 20 Dec 2024 16:45:20 +0530 Subject: [PATCH] Implemented the Close() method --- memoria.go | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/memoria.go b/memoria.go index 91ff36d..2539030 100644 --- a/memoria.go +++ b/memoria.go @@ -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 +}