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:org.elasticlib.node.repository.StagingSessionsCache.java

/**
 * Constructor./* w ww.  ja v  a  2  s .c  o m*/
 *
 * @param name repository name.
 * @param config Configuration holder.
 * @param taskManager Asynchronous tasks manager.
 */
public StagingSessionsCache(String name, Config config, TaskManager taskManager) {
    cache = CacheBuilder.newBuilder().maximumSize(config.getInt(NodeConfig.STAGING_SESSIONS_MAX_SIZE))
            .expireAfterWrite(duration(config, NodeConfig.STAGING_SESSIONS_TIMEOUT),
                    unit(config, NodeConfig.STAGING_SESSIONS_TIMEOUT))
            .build();

    if (config.getBoolean(NodeConfig.STAGING_SESSIONS_CLEANUP_ENABLED)) {
        cleanUpTask = taskManager.schedule(duration(config, NodeConfig.STAGING_SESSIONS_CLEANUP_INTERVAL),
                unit(config, NodeConfig.STAGING_SESSIONS_CLEANUP_INTERVAL),
                "[" + name + "] Evicting expired staging sessions", () -> cache.cleanUp());
    } else {
        cleanUpTask = null;
    }
}

From source file:com.facebook.buck.util.DefaultFileHashCache.java

public DefaultFileHashCache(ProjectFilesystem projectFilesystem, Console console) {
    this.projectFilesystem = Preconditions.checkNotNull(projectFilesystem);
    this.console = Preconditions.checkNotNull(console);

    this.loadingCache = CacheBuilder.newBuilder().build(new CacheLoader<Path, HashCode>() {
        @Override// ww  w. j  a  v a  2  s .c  o  m
        public HashCode load(Path path) throws Exception {
            File file = DefaultFileHashCache.this.projectFilesystem.resolve(path).toFile();
            InputSupplier<? extends InputStream> inputSupplier = Files.newInputStreamSupplier(file);
            return ByteStreams.hash(inputSupplier, Hashing.sha1());
        }
    });
}

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

public GroupsProviderLdapClientCacheDecorator(GroupsProviderLdapClient underlyingClient, Duration ttl) {
    this.underlyingClient = underlyingClient;
    this.ldapUserGroupsCache = CacheBuilder.newBuilder().expireAfterWrite(ttl.toMillis(), TimeUnit.MILLISECONDS)
            .build();//from w  w w .j  av  a  2  s  .c o  m
    authenticationLdapClientCacheDecorator = new AuthenticationLdapClientCacheDecorator(underlyingClient, ttl);
}

From source file:me.defying.chili.memoize.MemoizeCacheLoader.java

@Override
public Cache<Object, Optional<Object>> load(Method key) throws Exception {
    CacheBuilder<Object, Object> builder = CacheBuilder.newBuilder();
    Memoize annotation = key.getAnnotation(Memoize.class);

    if (annotation.size() > 0) {
        builder.maximumSize(annotation.size());
    }/*from  ww  w  . j a va  2 s.  com*/

    if (annotation.time() > 0) {
        builder.expireAfterWrite(annotation.time(), annotation.unit());
    }

    if (annotation.statistics()) {
        builder.recordStats();
    }

    return builder.build();
}

From source file:se.uu.it.cs.recsys.ruleminer.config.CourseRecommenderRuleMinerSpringConfig.java

@Bean
public CacheManager cacheManager() {
    SimpleCacheManager cacheManager = new SimpleCacheManager();

    GuavaCache fpTreeCache = new GuavaCache("FPTrees",
            CacheBuilder.newBuilder().expireAfterWrite(1, TimeUnit.DAYS).maximumSize(100).build());

    GuavaCache fpPatternCache = new GuavaCache("FPPatterns",
            CacheBuilder.newBuilder().expireAfterWrite(1, TimeUnit.DAYS).maximumSize(100).build());

    cacheManager.setCaches(Stream.of(fpTreeCache, fpPatternCache).collect(Collectors.toList()));

    return cacheManager;
}

From source file:com.onboard.web.api.utils.AvatarUtils.java

@PostConstruct
public void init() {
    defaultAvatarUrl = String.format("%s%s/avatar/default.png", configuration.getUpyunProtocol(),
            configuration.getUpyunHost());
    userCache = CacheBuilder.newBuilder().maximumSize(1000).build(new CacheLoader<String, String>() {
        @Override/*from   w ww .  j  a  v  a  2  s  . c o m*/
        public String load(String key) throws Exception {
            User user = userService.getUserByEmail(key.split(",")[0]);

            return getAvatarByUser(user, key.split(",")[1]);
        }
    });
}

From source file:uk.q3c.krail.i18n.DefaultPatternSource.java

@Inject

protected DefaultPatternSource(PatternCacheLoader cacheLoader) {
    //CacheLoader has no interface so the cast is necessary to allow alternative PatternCacheLLoader implementations
    //although all implementations would need to extend CacheLoader
    cache = CacheBuilder.newBuilder().build((CacheLoader) cacheLoader);
    // TODO will be using a config object
}

From source file:org.haiku.haikudepotserver.pkg.RenderedPkgIconRepositoryImpl.java

public RenderedPkgIconRepositoryImpl(HvifRenderingService hvifRenderingService,
        PngOptimizationService pngOptimizationService) {
    this.hvifRenderingService = hvifRenderingService;
    this.pngOptimizationService = pngOptimizationService;

    cache = CacheBuilder.newBuilder().maximumSize(256).expireAfterAccess(12, TimeUnit.HOURS).build();

    genericCache = CacheBuilder.newBuilder().maximumSize(10).expireAfterAccess(1, TimeUnit.HOURS).build();

}

From source file:org.ow2.play.governance.notification.wsn.AbstractSender.java

/**
 * //  w w w. ja  v  a 2 s . co  m
 */
public AbstractSender() {
    this.clients = CacheBuilder.newBuilder().maximumSize(100).expireAfterWrite(10L, TimeUnit.MINUTES)
            .removalListener(new RemovalListener<String, HTTPConsumerClient>() {
                public void onRemoval(RemovalNotification<String, HTTPConsumerClient> notification) {
                    System.out.println("Client removed from cache for endpoint " + notification.getKey());
                }
            }).build(new CacheLoader<String, HTTPConsumerClient>() {
                public HTTPConsumerClient load(String endpoint) {
                    System.out.println("Getting new client for endpoint " + endpoint);
                    return new HTTPConsumerClient(endpoint);
                }
            });
}

From source file:kr.debop4j.core.cache.FutureWebCacheRepository.java

/**
 * Instantiates a new Future web cache repository.
 */
public FutureWebCacheRepository() {
    cache = CacheBuilder.newBuilder().weakValues().build(getCacheLoader());
}