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.apache.usergrid.corepersistence.index.CollectionSettingsCacheImpl.java

public CollectionSettingsCacheImpl(MapManager mapManager, CollectionSettingsCacheFig indexSchemaCacheFig) {
    this.mapManager = mapManager;

    indexSchemaCache = CacheBuilder.newBuilder().maximumSize(indexSchemaCacheFig.getCacheSize())
            .expireAfterWrite(indexSchemaCacheFig.getCacheTimeout(), TimeUnit.MILLISECONDS)
            .build(new CacheLoader<String, Optional<Map<String, Object>>>() {
                @Override//www .j a  v a 2  s  .co m
                public Optional<Map<String, Object>> load(final String collectionName) throws Exception {
                    return Optional.fromNullable(retrieveCollectionSchema(collectionName));
                }
            });
}

From source file:com.cueup.hegemon.ScriptCache.java

/**
 * Create a ScriptCache that loads scripts from the given LoadPath.
 * @param loadPath the LoadPath to load files from.
 * @param scriptCompilation the strategy to use to compile scripts.
 *//*from  w  w w .j av a 2  s .  c om*/
public ScriptCache(final LoadPath loadPath, final ScriptCompilation scriptCompilation) {
    this.cache = CacheBuilder.newBuilder().build(new CacheLoader<String, Script>() {
        @Override
        public Script load(String key) throws Exception {
            return new Script(key, loadPath.load(key), scriptCompilation, loadPath);
        }
    });
}

From source file:com.facebook.buck.core.rules.resolver.impl.ActionGraphBuilderMetadataCache.java

ActionGraphBuilderMetadataCache(ActionGraphBuilder graphBuilder, TargetGraph targetGraph, int initialCapacity) {
    // Precondition (not checked): graphBuilder has the same targetGraph as the one passed in
    this.graphBuilder = graphBuilder;
    this.targetGraph = targetGraph;
    this.metadataCache = CacheBuilder.newBuilder().initialCapacity(initialCapacity)
            .build(new MetadataCacheLoader());
}

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

/**
 * Create a new GuavaCache with the specified name.
 * @param name the name of the cache/*  w w  w . ja  v a2s.c  o m*/
 * @param allowNullValues whether to accept and convert null values for this cache
 */
public GuavaCache(String name, boolean allowNullValues) {
    this(name, CacheBuilder.newBuilder(), allowNullValues);
}

From source file:com.devnexus.ting.core.service.impl.DefaultTwitterService.java

/**
 * Constructor that initializes the 'twitterMessages' Map as a simple LRU
 * cache holding a maximum of 20 messages.
 *//* ww  w.j a v  a2s  . c  o m*/
public DefaultTwitterService() {

    this.twitterMessages = CacheBuilder.newBuilder().maximumSize(40)
            .build(new CacheLoader<Long, TwitterMessage>() {
                public TwitterMessage load(Long key) {
                    return null;
                }
            });
}

From source file:org.esbtools.auth.util.RolesCache.java

public RolesCache(int expiryMS) {
    rolesCache = CacheBuilder.newBuilder().concurrencyLevel(concurrencyLevel).maximumSize(maximumSize)
            .expireAfterWrite(expiryMS, TimeUnit.MILLISECONDS)
            .removalListener(new RemovalListener<String, Set<String>>() {
                {/*from   w  w  w.j a v  a 2  s. c  o m*/
                    LOGGER.debug("Removal Listener created");
                }

                @Override
                public void onRemoval(RemovalNotification<String, Set<String>> notification) {
                    LOGGER.debug("This data from " + notification.getKey() + " evacuated due:"
                            + notification.getCause());
                }
            }).build();

    fallbackRolesCache = CacheBuilder.newBuilder().concurrencyLevel(concurrencyLevel) // handle 10 concurrent request without a problem
            .maximumSize(maximumSize) // Hold 500 sessions before remove them
            .build();

    LOGGER.info("RolesCache initialized with expiry={}", expiryMS);
}

From source file:net.identio.server.service.usersession.UserSessionService.java

@Autowired
public UserSessionService(UserSessionConfiguration config) {

    LOG.debug("Initializing in-memory session service");

    sessionCache = CacheBuilder.newBuilder().maximumSize(100000)
            .expireAfterAccess(config.getDuration(), TimeUnit.MINUTES)
            .build(new CacheLoader<String, UserSession>() {
                public UserSession load(@Nonnull String o) {
                    return new UserSession();
                }/*from  w  ww.j  a  v  a  2  s  .  c  o  m*/
            });

    LOG.debug("* Successfully created session cache");
}

From source file:com.google.dart.engine.internal.index.file.CachingNodeManager.java

public CachingNodeManager(NodeManager manager) {
    this.manager = manager;
    {//from   www  .ja  va2 s  . c  o  m
        CacheBuilder<Object, Object> builder = CacheBuilder.newBuilder();
        cache = builder.maximumSize(64).expireAfterAccess(5, TimeUnit.SECONDS).build();
    }
    new CleanUpThread().start();
}

From source file:org.apache.usergrid.corepersistence.index.IndexSchemaCacheImpl.java

public IndexSchemaCacheImpl(MapManager mapManager, IndexSchemaCacheFig indexSchemaCacheFig) {
    this.mapManager = mapManager;
    indexSchemaCache = CacheBuilder.newBuilder().maximumSize(indexSchemaCacheFig.getCacheSize())
            .expireAfterWrite(indexSchemaCacheFig.getCacheTimeout(), TimeUnit.MILLISECONDS)
            .build(new CacheLoader<String, Optional<Map>>() {
                @Override/*from w w  w.j  a v a2 s. c o  m*/
                public Optional<Map> load(final String collectionName) throws Exception {
                    return Optional.fromNullable(retrieveCollectionSchema(collectionName));
                }
            });
}

From source file:com.voxelplugineering.voxelsniper.world.queue.CommonOfflineUndoHandler.java

/**
 * Creates a new {@link CommonOfflineUndoHandler}.
 *//*from w  w w  . j  a  v a 2  s  .c  o m*/
public CommonOfflineUndoHandler() {
    this.cache = CacheBuilder.newBuilder().expireAfterAccess(60, TimeUnit.MINUTES).build();
}