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

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

Introduction

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

Prototype

public static CacheBuilder<Object, Object> newBuilder() 

Source Link

Document

Constructs a new CacheBuilder instance with default settings, including strong keys, strong values, and no automatic eviction of any kind.

Usage

From source file:cc.kune.wave.server.CustomGadgetProviderServlet.java

@Inject
public CustomGadgetProviderServlet(@Named(CoreSettings.RESOURCE_BASES) final List<String> resourceBases) {
    jsonCache = CacheBuilder.newBuilder().expireAfterWrite(5, TimeUnit.MINUTES)
            .build(new CacheLoader<String, String>() {
                @Override/*from  ww w  .ja va 2s  .  com*/
                public String load(final String key) {
                    String jsonString = "";
                    try {
                        jsonString = FileDownloadManagerUtils.getInpuStreamAsString(FileDownloadManagerUtils
                                .getInputStreamInResourceBases(resourceBases, "/others/jsongadgets.json"));

                    } catch (final IOException e) {
                        LOG.log(Level.WARNING, "Error while loading gadgets json", e);
                    }
                    return jsonString;
                }
            });
}

From source file:org.ygl.plexc.PlexcEngine.java

private PlexcEngine() {
    this.policyCache = CacheBuilder.newBuilder().maximumSize(128).build(new CacheLoader<String, PlexcPolicy>() {
        @Override//from  w  ww.  j av  a  2s  .  com
        public PlexcPolicy load(String email) throws Exception {
            email = Utils.unquote(email);
            User user = User.findByEmail(email);
            return new PlexcPolicy(user);
        }
    });
}

From source file:alluxio.master.file.meta.LazyUfsBlockLocationCache.java

/**
 * Creates a new instance of {@link UfsBlockLocationCache}.
 *
 * @param mountTable the mount table/*  w  w w  .  j  a  v a2  s . co  m*/
 */
public LazyUfsBlockLocationCache(MountTable mountTable) {
    mCache = CacheBuilder.newBuilder().maximumSize(MAX_BLOCKS).build();
    mMountTable = mountTable;
}

From source file:org.jooby.internal.RouteMetadata.java

public RouteMetadata(final Env env) {
    CacheLoader<Class<?>, Map<String, Object>> loader = CacheLoader.from(RouteMetadata::extractMetadata);

    cache = env.name().equals("dev") ? CacheBuilder.newBuilder().maximumSize(0).build(loader)
            : CacheBuilder.newBuilder().build(loader);
}

From source file:uk.ac.cam.cl.dtg.segue.api.monitors.InMemoryMisuseMonitor.java

/**
 * Creates a misuse monitor that just uses non-persistent storage.
 *//* www .  j  a va 2s. com*/
@Inject
public InMemoryMisuseMonitor() {
    nonPersistentDatabase = CacheBuilder.newBuilder()
            .expireAfterAccess(2, TimeUnit.DAYS).<String, Map<String, Map.Entry<Date, Integer>>>build();
    handlerMap = Maps.newConcurrentMap();
}

From source file:gobblin.data.management.copy.CopyContext.java

public CopyContext() {
    this.fileStatusCache = CacheBuilder.newBuilder().recordStats().maximumSize(10000).build();
}

From source file:org.waveprotocol.examples.robots.echoey.Echoey.java

public Echoey() {
    shadowBlipMap = CacheBuilder.newBuilder().expireAfterWrite(1, TimeUnit.HOURS).<String, String>build()
            .asMap();
}

From source file:stubble.core.HandleBarsTemplateEngine.java

/**
 * Constructs a handlebars template engine
 *
 * @param resourceRoot the resource root
 *//*from  w ww. j  a  v  a2  s . co  m*/
public HandleBarsTemplateEngine(String resourceRoot) {
    TemplateLoader templateLoader = new FileTemplateLoader(resourceRoot);
    templateLoader.setPrefix(resourceRoot);
    templateLoader.setSuffix(null);

    handlebars = new Handlebars(templateLoader);

    // Set Guava cache.
    Cache<TemplateSource, Template> cache = CacheBuilder.newBuilder().expireAfterWrite(10, TimeUnit.MINUTES)
            .maximumSize(1000).build();

    handlebars = handlebars.with(new GuavaTemplateCache(cache));
}

From source file:org.onebusaway.presentation.services.cachecontrol.SiriCacheServiceImpl.java

@Override
@Refreshable(dependsOn = { SIRI_CACHE_TIMEOUT_KEY })
protected synchronized void refreshCache() {
    if (_cache == null)
        return;/*ww  w  .  j  a  v a  2  s.com*/
    int timeout = DEFAULT_CACHE_TIMEOUT;
    _log.info("rebuilding siri cache with " + _cache.size() + " entries after refresh with timeout=" + timeout
            + "...");
    ConcurrentMap<Integer, String> map = _cache.asMap();
    _cache = CacheBuilder.newBuilder().expireAfterWrite(timeout, TimeUnit.SECONDS).build();
    for (Entry<Integer, String> entry : map.entrySet()) {
        _cache.put(entry.getKey(), entry.getValue());
    }
    _log.info("done");
}

From source file:tech.beshu.ror.acl.definitions.ldaps.caching.AuthenticationLdapClientCacheDecorator.java

public AuthenticationLdapClientCacheDecorator(AuthenticationLdapClient underlyingClient, Duration ttl) {
    this.underlyingClient = underlyingClient;
    this.ldapUsersWithPasswordCache = CacheBuilder.newBuilder()
            .expireAfterWrite(ttl.toMillis(), TimeUnit.MILLISECONDS).build();
    this.badCredentialsCache = CacheBuilder.newBuilder().expireAfterWrite(ttl.toMillis(), TimeUnit.MILLISECONDS)
            .build();//from  w w w .  j  a  va 2  s.c  o  m
    this.ldapUsersCache = CacheBuilder.newBuilder().expireAfterWrite(ttl.toMillis(), TimeUnit.MILLISECONDS)
            .build();
}