Beispiel #1
0
 public void testTimeToIdle_negative() {
   CacheBuilder<Object, Object> builder = new CacheBuilder<Object, Object>();
   try {
     builder.expireAfterAccess(-1, SECONDS);
     fail();
   } catch (IllegalArgumentException expected) {
   }
 }
  public HashMapCacheRepository(long validFor) {
    if (validFor > 0) setExpiry(validFor);

    CacheBuilder builder = CacheBuilder.newBuilder();

    if (validFor > 0) builder.expireAfterAccess(validFor, TimeUnit.MINUTES);

    cache = builder.build();
  }
Beispiel #3
0
 public void testTimeToIdle_setTwice() {
   CacheBuilder<Object, Object> builder =
       new CacheBuilder<Object, Object>().expireAfterAccess(3600, SECONDS);
   try {
     // even to the same value is not allowed
     builder.expireAfterAccess(3600, SECONDS);
     fail();
   } catch (IllegalStateException expected) {
   }
 }
 @PostConstruct
 private void init() {
   CacheBuilder<Object, Object> builder = CacheBuilder.newBuilder();
   Cache<Serializable, WebSession> graphs =
       builder
           .expireAfterAccess(expireTime, TimeUnit.SECONDS)
           .initialCapacity(1000)
           .removalListener(listener)
           .build();
   memoryRepository = new ExpiredCache<Serializable, WebSession>(graphs);
 }
 @SuppressWarnings({"rawtypes", "unchecked"})
 @PostConstruct
 private void init() {
   String cacheName = getActiveSessionsCacheName();
   CacheBuilder<Object, Object> builder = CacheBuilder.newBuilder();
   com.google.common.cache.Cache graphs =
       builder
           .expireAfterAccess(30, TimeUnit.MINUTES)
           .initialCapacity(10000)
           .removalListener(listener)
           .build();
   org.springframework.cache.Cache guavaCache = new GuavaCache(cacheName, graphs);
   Cache cache = new DelegateCache(guavaCache);
   setActiveSessionsCache(cache);
 }
  <K, V> void configureCacheBuilder(
      CompleteConfiguration<K, V> completeConfiguration,
      CacheBuilder<Object, Object> cacheBuilder) {
    ExpiryPolicy expiryPolicy = completeConfiguration.getExpiryPolicyFactory().create();

    Duration expiryForAccess = expiryPolicy.getExpiryForAccess();
    if (expiryForAccess != null && !expiryForAccess.isEternal()) {
      cacheBuilder.expireAfterAccess(
          expiryForAccess.getDurationAmount(), expiryForAccess.getTimeUnit());
    }
    Duration expiryForUpdate = expiryPolicy.getExpiryForUpdate();
    if (expiryForUpdate != null && !expiryForUpdate.isEternal()) {
      cacheBuilder.expireAfterWrite(
          expiryForUpdate.getDurationAmount(), expiryForUpdate.getTimeUnit());
    }
  }
  private void buildCache() {
    long sizeInBytes =
        MemorySizeValue.parseBytesSizeValueOrHeapRatio(size, INDICES_CACHE_QUERY_SIZE).bytes();

    CacheBuilder<Key, Value> cacheBuilder =
        CacheBuilder.newBuilder()
            .maximumWeight(sizeInBytes)
            .weigher(new QueryCacheWeigher())
            .removalListener(this);
    cacheBuilder.concurrencyLevel(concurrencyLevel);

    if (expire != null) {
      cacheBuilder.expireAfterAccess(expire.millis(), TimeUnit.MILLISECONDS);
    }

    cache = cacheBuilder.build();
  }
 public com.google.common.cache.CacheBuilder<Object, Object> expireAfterAccess(
     long duration, TimeUnit unit) {
   return builder.expireAfterAccess(duration, unit);
 }
 @Override
 public void applyExpiration(final CacheBuilder<?, ?> builder, final Period period) {
   builder.expireAfterAccess(period.duration, period.durationUnit);
 }