首页 > 解决方案 > 使用 Closeable 加载缓存

问题描述

使用 LoadingCache 时如何处理 Closeable 对象?

我是否需要保存对我在build通话中的引用,并在创建新的之前关闭它?

private final LoadingCache<String, BigtableDataClient> DATA_CLIENT_LOADING_CACHE = CacheBuilder.newBuilder()
            .refreshAfterWrite(50, TimeUnit.MINUTES)
            .build(new CacheLoader<String, BigtableDataClient>() {
                @Override
                public BigtableDataClient load(final String key) {
... // in here?
                }

标签: dispose

解决方案


推荐阅读