You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@shenyu.apache.org by ttttangzhen <28...@qq.com> on 2021/05/17 06:53:08 UTC

There may be a wrong way to use guava cache

in&nbsp;org.apache.shenyu.plugin.apache.dubbo.cache.ApplicationConfigCache&nbsp;and ApplicationConfigCache in other RPC plugin
private final LoadingCache<String, ReferenceConfig<GenericService&gt;&gt; cache = CacheBuilder.newBuilder()             .maximumWeight(maxCount)             .weigher((Weigher<String, ReferenceConfig<GenericService&gt;&gt;) (string, referenceConfig) -&gt; getSize())             .removalListener(notification -&gt; {                 // ignore...             })             .build(new CacheLoader<String, ReferenceConfig<GenericService&gt;&gt;() {                 // ignore...             }); private int getSize() {     return (int) cache.size(); } 

Here, weight is used to control the total capacity of&nbsp;guava cache, but the weight of each cache use&nbsp;getSize,it represents the total number of items cached when a piece of data is cached.

I think there may be wrong usage here, If we use weights, the weights should represent the size of each piece of data
, so here should be replaced by the number of bars to control the total capacity