本文介绍了Guava缓存侦听器,用于插入的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们发现在Google Guava中使用AddListener补充RemovalListener非常有用.

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

AddListener是否有合适的替代品,可以补充RemovalListener?

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

推荐答案

您可以自己提供-只需将自定义侦听器传递给计算Function,并且每当计算一个值时,都将通知侦听器.

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

如果您使用的是asMap().put(..),则必须将整个内容包装在您的自定义类中,该类既委托原始对象,又调用附加侦听器.

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.

这篇关于Guava缓存侦听器,用于插入的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-23 01:45