You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The current behavior of Purge() is such that the EvictedFunc() is not called when items are removed from the cache (the cached items lists are just replaced and handed off to the GC). Without a higher-level locking primitive, there is not a way to purge a cache and call the evict handler.
It would be nice if the interface was updated to include PurgeExpire() that would take c.mu.Lock() and, if evictedFunc() is not nil, call GetALL() + evictedFunc() on each of the items while c.mu held and before c.init() is called.
Or Purge() could be updated to implicitly call evictFunc() on each item. Without this change to make Purge() symmetric w/ calls to LoaderFunc(), it is difficult to use this cache for finite resources (e.g. file descriptors). Resorting to finalizers used in the LoaderFunc() feels very distasteful and like a hack.
I'm happy to PR this change but want to inquire re: the API first before submitting a PR.
The text was updated successfully, but these errors were encountered:
The current behavior of
Purge()
is such that theEvictedFunc()
is not called when items are removed from the cache (the cached items lists are just replaced and handed off to the GC). Without a higher-level locking primitive, there is not a way to purge a cache and call the evict handler.It would be nice if the interface was updated to include
PurgeExpire()
that would takec.mu.Lock()
and, ifevictedFunc()
is notnil
, callGetALL()
+evictedFunc()
on each of the items whilec.mu
held and beforec.init()
is called.Or
Purge()
could be updated to implicitly callevictFunc()
on each item. Without this change to makePurge()
symmetric w/ calls toLoaderFunc()
, it is difficult to use this cache for finite resources (e.g. file descriptors). Resorting to finalizers used in theLoaderFunc()
feels very distasteful and like a hack.I'm happy to PR this change but want to inquire re: the API first before submitting a PR.
The text was updated successfully, but these errors were encountered: