Guava cache listener for insertions

2019-07-21 17:06发布

问题:

We'd find it very useful to have an AddListener to complement RemovalListener in Google Guava.

Is there a suitable alternative to an AddListener that would complement RemovalListener?

回答1:

You can provide that yourself - just pass your custom listener to your computing Function, and whenever you compute a value, notify the listener.

If you are using asMap().put(..), then you'd have to wrap the whole thing in in your custom classes that delegate to the originals but also invoke the addition listener.



标签: java guava