go-cache icon indicating copy to clipboard operation
go-cache copied to clipboard

Add new method GetItemsAndFlush

Open oGabrielArruda opened this issue 5 months ago • 4 comments

We are facing a situation where we need to flush the entire cache while capturing a snapshot of its exact state before doing so.

Using the Itemsfunction followed by Flush is not concurrent safe because a Set operation could occur between the two calls, resulting in the Flush call mistakenly deleting newly added items.

A workaround would be to use a mutex that prevents writes while these two sequential calls are being made. However, it is much simpler and more efficient to use the library's existing mutex.

oGabrielArruda avatar Sep 04 '24 01:09 oGabrielArruda