Example usage for com.google.common.cache CacheBuilder from

List of usage examples for com.google.common.cache CacheBuilder from

Introduction

In this page you can find the example usage for com.google.common.cache CacheBuilder from.

Prototype

@GwtIncompatible("To be supported")
public static CacheBuilder<Object, Object> from(String spec) 

Source Link

Document

Constructs a new CacheBuilder instance with the settings specified in spec .

Usage

From source file:com.google.javascript.jscomp.transpile.TranspilerBuilder.java

/**
 * Returns a TranspilerBuilder with cached transpilations, using the given cache spec. Note that
 * the builder itself is not changed.//from ww w . j av  a  2s .  c om
 */
@CheckReturnValue
public TranspilerBuilder caching(String spec) {
    return caching(CacheBuilder.from(spec));
}

From source file:com.vsct.dt.hesperides.security.CorrectedCachingAuthenticator.java

/**
 * Creates a new cached authenticator.//w  ww.j a v  a  2  s .co  m
 *
 * @param metricRegistry the application's registry of metrics
 * @param authenticator  the underlying authenticator
 * @param cacheSpec      a {@link CacheBuilderSpec}
 */
public CorrectedCachingAuthenticator(MetricRegistry metricRegistry, Authenticator<C, P> authenticator,
        CacheBuilderSpec cacheSpec) {
    this(metricRegistry, authenticator, CacheBuilder.from(cacheSpec));
}

From source file:org.springmodules.cache.guava.GuavaCache.java

/**
 * Create a new GuavaCache using the specified name and {@link CacheBuilderSpec specification}
 * @param name the name of the cache//  w w w.  j a v  a  2 s .c  om
 * @param spec the cache builder specification to use to build he cache
 */
public GuavaCache(String name, CacheBuilderSpec spec, boolean allowNullValues) {
    this(name, CacheBuilder.from(spec), allowNullValues);
}

From source file:cherry.foundation.workday.WorkdayManagerImpl.java

@Override
public void afterPropertiesSet() {
    numberOfWorkdayCache = CacheBuilder.from(numberOfWorkdayCacheSpec)
            .build(new CacheLoader<Triple<String, LocalDate, LocalDate>, Integer>() {
                @Override//from  w  w w.  ja v a2 s  .c  om
                public Integer load(Triple<String, LocalDate, LocalDate> key) {
                    return workdayStore.getNumberOfWorkday(key.getLeft(), key.getMiddle(), key.getRight());
                }
            });
    nextWorkdayCache = CacheBuilder.from(nextWorkdayCacheSpec)
            .build(new CacheLoader<Triple<String, LocalDate, Integer>, LocalDate>() {
                @Override
                public LocalDate load(Triple<String, LocalDate, Integer> key) {
                    return workdayStore.getNextWorkday(key.getLeft(), key.getMiddle(), key.getRight());
                }
            });
}

From source file:cherry.foundation.code.CodeManagerImpl.java

@Override
public void afterPropertiesSet() {
    entryCache = CacheBuilder.from(entryCacheSpec).build(new CacheLoader<Pair<String, String>, CodeEntry>() {
        @Override//  w  w  w. j  ava2  s. c om
        public CodeEntry load(Pair<String, String> key) {
            return ObjectUtils.firstNonNull(codeStore.findByValue(key.getLeft(), key.getRight()), nullEntry);
        }
    });
    listCache = CacheBuilder.from(listCacheSpec).build(new CacheLoader<String, List<CodeEntry>>() {
        @Override
        public List<CodeEntry> load(String key) {
            return codeStore.getCodeList(key);
        }
    });
}

From source file:com.davidbracewell.reflection.BeanDescriptorCache.java

protected BeanDescriptorCache() {
    String spec = Config.get(BeanDescriptorCache.class, "spec")
            .asString("maximumSize=100,expireAfterWrite=10m");
    cache = CacheBuilder.from(spec).build(new CacheLoader<Class<?>, BeanDescriptor>() {
        public BeanDescriptor load(Class<?> key) {
            return new BeanDescriptor(key);
        }/* w  ww  .  j  av  a2 s . co m*/
    });
}

From source file:librec.ranking.WBPR.java

@Override
protected void initModel() throws Exception {
    super.initModel();

    itemBias = new DenseVector(numItems);
    itemBias.init(smallValue);/*w  w  w  .j a v a 2s.  c  o  m*/

    userItemsCache = trainMatrix.rowColumnsCache(cacheSpec);

    // pre-compute and sort by item's popularity
    sortedItemPops = new ArrayList<>();
    for (int i = 0; i < numItems; i++) {
        sortedItemPops.add(new AbstractMap.SimpleEntry<Integer, Double>(i, trainMatrix.columnSize(i) + 0.0));
    }
    Lists.sortList(sortedItemPops, true);

    // cache each user's candidate items with probabilities
    cacheItemProbs = CacheBuilder.from(cacheSpec)
            .build(new CacheLoader<Integer, List<Entry<Integer, Double>>>() {

                @Override
                public List<Entry<Integer, Double>> load(Integer u) throws Exception {
                    List<Entry<Integer, Double>> itemProbs = new ArrayList<>();

                    List<Integer> ratedItems = userItemsCache.get(u);

                    // filter candidate items
                    double sum = 0;
                    for (Entry<Integer, Double> itemPop : sortedItemPops) {
                        Integer item = itemPop.getKey();
                        double popularity = itemPop.getValue();

                        if (!ratedItems.contains(item) && popularity > 0) {
                            // make a clone to prevent bugs from normalization
                            itemProbs.add(new AbstractMap.SimpleEntry<Integer, Double>(itemPop));
                            sum += popularity;
                        }
                    }

                    // normalization
                    for (Entry<Integer, Double> itemProb : itemProbs) {
                        itemProb.setValue(itemProb.getValue() / sum);
                    }

                    return itemProbs;
                }
            });
}

From source file:org.springmodules.cache.guava.GuavaCacheManager.java

private CacheBuilder<Object, Object> getCacheBuilder() {
    if (cacheBuilder == null) {
        synchronized (this) {
            if (cacheBuilder == null) {
                if (StringUtils.hasText(spec)) {
                    cacheBuilder = CacheBuilder.from(spec);
                } else {
                    cacheBuilder = CacheBuilder.newBuilder();
                }/*from w w w  . j a  v a2 s  .c  om*/
            }
            notify();
        }
    }

    return cacheBuilder;
}

From source file:collene.SuckyExpiringCachingIO.java

private void ensureCache(final String key) {
    if (mcache.get(key) == null) {
        String interned = key.intern();
        synchronized (interned) {
            if (mcache.get(key) != null) {
                return;
            }//from   ww w .j  a v  a  2s .c  om

            LoadingCache<Long, byte[]> rowCache = CacheBuilder.from(cacheSpec)
                    .build(new CacheLoader<Long, byte[]>() {
                        @Override
                        public byte[] load(final Long col) throws Exception {
                            byte[] value = io.get(key, col);
                            if (value == null) {
                                value = NULL_SENTINAL;
                            }
                            return value;
                        }
                    });
            mcache.put(key, rowCache);
        }
    }
}

From source file:org.apache.openaz.xacml.std.pip.engines.StdConfigurableEngine.java

@Override
public void configure(String id, Properties properties) throws PIPException {
    this.setName(properties.getProperty(id + "." + PROP_NAME, id));
    this.setDescription(properties.getProperty(id + "." + PROP_DESCRIPTION));
    this.setIssuer(properties.getProperty(id + "." + PROP_ISSUER));
    /*//from w ww  . ja v a  2s.  co  m
     * Configure the cache IF it is defined
     */
    if (properties.getProperty(id + "." + PROP_CACHESPEC) != null) {
        this.cache = CacheBuilder.from(properties.getProperty(id + "." + PROP_CACHESPEC)).build();
    }
}