SchemaBranchCache.java 文件源码

java
阅读 31 收藏 0 点赞 0 评论 0

项目:registry 作者:
public SchemaBranchCache(Integer size, Long expiryInSecs, final SchemaBranchFetcher schemaBranchFetcher) {
    schemaBranchNameToIdMap = Maps.synchronizedBiMap(HashBiMap.create());
    loadingCache = CacheBuilder.newBuilder()
            .maximumSize(size)
            .expireAfterAccess(expiryInSecs, TimeUnit.SECONDS)
            .build(new CacheLoader<Key, SchemaBranch>() {
                @Override
                public SchemaBranch load(Key key) throws Exception {
                    SchemaBranch schemaBranch;
                    Key otherKey;
                    if (key.getSchemaBranchKey() != null) {
                        schemaBranch = schemaBranchFetcher.getSchemaBranch(key.getSchemaBranchKey());
                        otherKey = Key.of(schemaBranch.getId());
                        schemaBranchNameToIdMap.put(key.getSchemaBranchKey(), schemaBranch.getId());
                    } else if (key.getId() != null) {
                        schemaBranch = schemaBranchFetcher.getSchemaBranch(key.getId());
                        otherKey = Key.of(new SchemaBranchKey(schemaBranch.getName(), schemaBranch.getSchemaMetadataName()));
                        schemaBranchNameToIdMap.put(otherKey.schemaBranchKey, schemaBranch.getId());
                    } else {
                        throw new IllegalArgumentException("Given argument is not valid: " + key);
                    }
                    loadingCache.put(otherKey, schemaBranch);
                    return schemaBranch;
                }
            });
}
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号