jellydator / ttlcache

An in-memory cache with item expiration and generics
MIT License
883 stars 115 forks source link

OnEviction doesn't work as expected #88

Closed davyzhang closed 1 year ago

davyzhang commented 1 year ago

https://go.dev/play/p/rmBTONl0npV

The example program doesn't compile

I changed it a little, but nothing happens

swithek commented 1 year ago

Your program exits before the event functions are even allowed to start. From the OnEviction docs: The function is executed on a separate goroutine and does not block the flow of the cache manager.

Here's how it should look like to be able to work: https://go.dev/play/p/Y7sOej0cy_1