Skip to content

Seemingly inconsistent invocations of eviction and removal listeners. #644

Answered by ben-manes
valmaltsev asked this question in Q&A
Discussion options

You must be logged in to vote

For explicit invalidation you can use the asMap().compute methods, where a null return value causes the entry to be removed. As the computation is atomic, this can perform custom logic and it is more idiomatic as how you would do so in with ConcurrentHashMap (versus a plain remove(key)).

For refresh this operation is computed asynchronously. It invokes CacheLoader#reload(key, oldValue) via its asyncReload default method. There is no atomic listener here, but the intent is that you already had the old value to evaluate with. If the entry changes so that the reload is invalid then the replacement is discarded (with the new value notified as replaced). There isn't an atomic listener for this…

Replies: 1 comment 2 replies

Comment options

You must be logged in to vote
2 replies
@valmaltsev
Comment options

@ben-manes
Comment options

Answer selected by ben-manes
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants