当前位置: 首页>>代码示例>>Java>>正文


Java Cache.get方法代码示例

本文整理汇总了Java中com.google.common.cache.Cache.get方法的典型用法代码示例。如果您正苦于以下问题:Java Cache.get方法的具体用法?Java Cache.get怎么用?Java Cache.get使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在com.google.common.cache.Cache的用法示例。


在下文中一共展示了Cache.get方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: get

import com.google.common.cache.Cache; //导入方法依赖的package包/类
@SuppressWarnings("unchecked")
public <T> T get(String cacheName, String key) {
    try {
        Cache<String, Object> cache = getCacheHolder(cacheName);
        if (cache != null) {
            Object result = cache.get(key, new Callable<Object>() {
                @Override
                public Object call() throws Exception {
                    return _NULL;
                }
            });
            if (result != null && !_NULL.equals(result)) {
                return (T) result;
            }
        }
    } catch (Exception e) {
        logger.warn("get LEVEL1 cache error", e);
    }
    return null;
}
 
开发者ID:warlock-china,项目名称:azeroth,代码行数:21,代码来源:GuavaLevel1CacheProvider.java

示例2: get

import com.google.common.cache.Cache; //导入方法依赖的package包/类
private Schema<?> get(final Class<?> cls, Cache<Class<?>, Schema<?>> cache) {
    try {
        return cache.get(cls, () -> RuntimeSchema.createFrom(cls));
    } catch (ExecutionException e) {
        return null;
    }
}
 
开发者ID:yu199195,项目名称:happylifeplat-transaction,代码行数:8,代码来源:SchemaCache.java

示例3: get

import com.google.common.cache.Cache; //导入方法依赖的package包/类
private Schema<?> get(final Class<?> cls, Cache<Class<?>, Schema<?>> cache) {
    try {
        return cache.get(cls, new Callable() {
            @Override
            public Object call() throws Exception {
                return RuntimeSchema.createFrom(cls);
            }
        });
    } catch (ExecutionException e) {
        return null;
    }
}
 
开发者ID:1991wangliang,项目名称:tx-lcn,代码行数:13,代码来源:SchemaCache.java

示例4: getUnchecked

import com.google.common.cache.Cache; //导入方法依赖的package包/类
static <K, V> V getUnchecked(Cache<K, V> cache, K key, Supplier<V> supplier) {
    try {
        return cache.get(key, supplier::get);
    } catch(ExecutionException e) {
        throw Throwables.propagate(e);
    }
}
 
开发者ID:OvercastNetwork,项目名称:ProjectAres,代码行数:8,代码来源:CacheUtils.java

示例5: getAndLoadIfNotPresent

import com.google.common.cache.Cache; //导入方法依赖的package包/类
private BitSet getAndLoadIfNotPresent(final Query query, final LeafReaderContext context) throws IOException, ExecutionException {
    final Object coreCacheReader = context.reader().getCoreCacheKey();
    final ShardId shardId = ShardUtils.extractShardId(context.reader());
    if (shardId != null // can't require it because of the percolator
            && index.getName().equals(shardId.getIndex()) == false) {
        // insanity
        throw new IllegalStateException("Trying to load bit set for index [" + shardId.getIndex()
                + "] with cache of index [" + index.getName() + "]");
    }
    Cache<Query, Value> filterToFbs = loadedFilters.get(coreCacheReader, new Callable<Cache<Query, Value>>() {
        @Override
        public Cache<Query, Value> call() throws Exception {
            context.reader().addCoreClosedListener(BitsetFilterCache.this);
            return CacheBuilder.newBuilder().build();
        }
    });
    return filterToFbs.get(query,new Callable<Value>() {
        @Override
        public Value call() throws Exception {
            final IndexReaderContext topLevelContext = ReaderUtil.getTopLevelContext(context);
            final IndexSearcher searcher = new IndexSearcher(topLevelContext);
            searcher.setQueryCache(null);
            final Weight weight = searcher.createNormalizedWeight(query, false);
            final Scorer s = weight.scorer(context);
            final BitSet bitSet;
            if (s == null) {
                bitSet = null;
            } else {
                bitSet = BitSet.of(s.iterator(), context.reader().maxDoc());
            }

            Value value = new Value(bitSet, shardId);
            listener.onCache(shardId, value.bitset);
            return value;
        }
    }).bitset;
}
 
开发者ID:baidu,项目名称:Elasticsearch,代码行数:38,代码来源:BitsetFilterCache.java

示例6: findCached

import com.google.common.cache.Cache; //导入方法依赖的package包/类
protected <T> T findCached(Class<T> type, Key key, Callable<T> c) {

        if (type == null || key == null) {
            return null;
        }

        Optional<?> cached;

        synchronized (type) {

            Cache<Key, Optional<?>> cache = singleCache.computeIfAbsent(type, t -> createCache());

            try {

                cached = cache.get(key, () -> {

                    T value = c.call();

                    log.trace("Cached : {} - {}", key, value);

                    return Optional.ofNullable(value);

                });

            } catch (Exception e) {

                log.warn("Failed to cache : {} - {}", type, e);

                cached = Optional.empty();

            }

        }

        return type.cast(cached.orElse(null));

    }
 
开发者ID:after-the-sunrise,项目名称:cryptotrader,代码行数:38,代码来源:TemplateContext.java

示例7: listCached

import com.google.common.cache.Cache; //导入方法依赖的package包/类
protected <T> List<T> listCached(Class<T> type, Key key, Callable<List<T>> c) {

        if (type == null || key == null) {
            return emptyList();
        }

        Optional<List<?>> cached;

        synchronized (type) {

            Cache<Key, Optional<List<?>>> cache = listCache.computeIfAbsent(type, t -> createCache());

            try {

                cached = cache.get(key, () -> {

                    List<T> values = trimToEmpty(c.call());

                    log.trace("Cached list : {} ({})", key, values.size());

                    return Optional.of(values);

                });

            } catch (Exception e) {

                log.warn("Failed to cache list : {} - {}", type, e);

                cached = Optional.empty();

            }

        }

        return cached.orElse(emptyList()).stream().map(type::cast).collect(Collectors.toList());

    }
 
开发者ID:after-the-sunrise,项目名称:cryptotrader,代码行数:38,代码来源:TemplateContext.java


注:本文中的com.google.common.cache.Cache.get方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。