From 2a6a617fe0c8e313aa38abdce5876d50ee246020 Mon Sep 17 00:00:00 2001 From: parMaster Date: Fri, 4 Aug 2023 18:19:13 +0300 Subject: [PATCH] WithCleanup option explained --- README.md | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/README.md b/README.md index f111aef..67b3ea3 100644 --- a/README.md +++ b/README.md @@ -133,16 +133,12 @@ Cleanup expired key-value pairs in the cache. You can call this method periodica cache.Cleanup() ``` -If you want to cleanup expired key-value periodically, you can run the `Cleanup` method in a goroutine with a time interval: +WithCleanup is a functional option to the NewCache constructor that allows you to specify a cleanup interval: ```go -go func() { - for { - cache.Cleanup() - time.Sleep(1 * time.Minute) // run every minute - } -}() +cache := mcache.NewCache(mcache.WithCleanup(60)) // cleanup every 60 seconds ``` +It will basically run a Cleanup method in a goroutine with a time interval. ## Tests and Benchmarks