当前位置: 首页>>代码示例>>Java>>正文


Java CacheEntry类代码示例

本文整理汇总了Java中org.cache2k.CacheEntry的典型用法代码示例。如果您正苦于以下问题:Java CacheEntry类的具体用法?Java CacheEntry怎么用?Java CacheEntry使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


CacheEntry类属于org.cache2k包,在下文中一共展示了CacheEntry类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: testEventPackage

import org.cache2k.CacheEntry; //导入依赖的package包/类
/**
 * Simple test to see whether event package is exported.
 */
@Test
public void testEventPackage() {
  CacheManager m = CacheManager.getInstance("testEventPackage");
  final AtomicInteger _count = new AtomicInteger();
  Cache<String, String> c =
    new Cache2kBuilder<String, String>() {}
      .manager(m)
      .eternal(true)
      .addListener(new CacheEntryCreatedListener<String, String>() {
        @Override
        public void onEntryCreated(final Cache<String, String> cache, final CacheEntry<String, String> entry) {
          _count.incrementAndGet();
        }
      })
      .build();
  c.put("abc", "123");
  assertTrue(c.containsKey("abc"));
  assertEquals("123", c.peek("abc"));
  assertEquals(1, _count.get());
  c.close();
}
 
开发者ID:cache2k,项目名称:cache2k,代码行数:25,代码来源:OsgiIT.java

示例2: replaceOrGet

import org.cache2k.CacheEntry; //导入依赖的package包/类
public Semantic<K, V, CacheEntry<K,V>> replaceOrGet(final K key, final V value,
                                                    final V newValue, final CacheEntry<K, V> dummyEntry) {
  return new Semantic.UpdateExisting<K, V, CacheEntry<K,V>>() {

    @Override
    public void update(Progress<K, V, CacheEntry<K, V>> c, ExaminationEntry<K, V> e) {
      if (c.isPresentOrMiss()) {
        if (e.getValueOrException().equals(value)) {
          c.result(null);
          c.put(newValue);
          return;
        }
        c.entryResult(e);
        return;
      }
      c.result(dummyEntry);
    }

  };
}
 
开发者ID:cache2k,项目名称:cache2k,代码行数:21,代码来源:Operations.java

示例3: keys

import org.cache2k.CacheEntry; //导入依赖的package包/类
/**
 * Key iteration on top of normal iterator.
 */
@Override
public Iterable<K> keys() {
  return new Iterable<K>() {
    @Override
    public Iterator<K> iterator() {
      final Iterator<CacheEntry<K,V>> it = BaseCache.this.iterator();
      return new Iterator<K>() {
        @Override
        public boolean hasNext() {
          return it.hasNext();
        }

        @Override
        public K next() {
          return it.next().getKey();
        }

        @Override
        public void remove() {
          throw new UnsupportedOperationException();
        }
      };
    }
  };
}
 
开发者ID:cache2k,项目名称:cache2k,代码行数:29,代码来源:BaseCache.java

示例4: customExecutor

import org.cache2k.CacheEntry; //导入依赖的package包/类
@Test
public void customExecutor() {
  final AtomicInteger _counter = new AtomicInteger();
  Cache<Integer, Integer> c =
    Cache2kBuilder.of(Integer.class, Integer.class)
      .addAsyncListener(new CacheEntryCreatedListener<Integer, Integer>() {
        @Override
        public void onEntryCreated(final Cache<Integer, Integer> cache, final CacheEntry<Integer, Integer> entry) {
        }
      })
      .asyncListenerExecutor(new Executor() {
        @Override
        public void execute(final Runnable command) {
          _counter.incrementAndGet();
        }
      })
      .build();
  c.put(1,2);
  c.close();
  assertEquals(1, _counter.get());
}
 
开发者ID:cache2k,项目名称:cache2k,代码行数:22,代码来源:ListenerTest.java

示例5: testAdvancedLoader

import org.cache2k.CacheEntry; //导入依赖的package包/类
@Test
public void testAdvancedLoader() {
  Cache<Integer,Integer> c = target.cache(new CacheRule.Specialization<Integer, Integer>() {
    @Override
    public void extend(final Cache2kBuilder<Integer, Integer> b) {
      b .loader(new AdvancedCacheLoader<Integer, Integer>() {
        @Override
        public Integer load(final Integer key, long currentTime, CacheEntry<Integer,Integer> e) throws Exception {
          return key * 2;
        }
      });
    }
  });
  assertEquals((Integer) 10, c.get(5));
  assertEquals((Integer) 20, c.get(10));
  assertFalse(c.containsKey(2));
  assertTrue(c.containsKey(5));
}
 
开发者ID:cache2k,项目名称:cache2k,代码行数:19,代码来源:CacheLoaderTest.java

示例6: almostEternal_expiryPolicy_noOverflow

import org.cache2k.CacheEntry; //导入依赖的package包/类
@Test
public void almostEternal_expiryPolicy_noOverflow() {
  long _BIG_VALUE = Long.MAX_VALUE - 47;
  TimingHandler h = TimingHandler.of(
    CLOCK,
    Cache2kBuilder.forUnknownTypes()
      .expiryPolicy(new ExpiryPolicy() {
        @Override
        public long calculateExpiryTime(final Object key, final Object value, final long loadTime, final CacheEntry oldEntry) {
          return ETERNAL;
        }
      })
      .expireAfterWrite(_BIG_VALUE, TimeUnit.MILLISECONDS)
      .toConfiguration()
  );
  long t = h.calculateNextRefreshTime(ENTRY, null, 0);
  assertEquals(_BIG_VALUE, t);
  t = h.calculateNextRefreshTime(ENTRY, null, 48);
  assertEquals(Long.MAX_VALUE, t);
}
 
开发者ID:cache2k,项目名称:cache2k,代码行数:21,代码来源:TimingHandlerTest.java

示例7: policy_sharp

import org.cache2k.CacheEntry; //导入依赖的package包/类
/**
 * Sharp is honored in the calculation phase.
 */
@Test
public void policy_sharp() {
  TimingHandler h = TimingHandler.of(
    CLOCK,
    Cache2kBuilder.forUnknownTypes()
      .expiryPolicy(new ExpiryPolicy() {
        @Override
        public long calculateExpiryTime(Object key, Object value, long loadTime, CacheEntry oldEntry) {
          return loadTime + 1;
        }
      })
      .sharpExpiry(true)
      .toConfiguration()
  );
  Entry e = new Entry();
  long t = h.calculateNextRefreshTime(e, null, NOW);
  assertEquals(-NOW - 1, t);
}
 
开发者ID:cache2k,项目名称:cache2k,代码行数:22,代码来源:TimingHandlerTest.java

示例8: expireAfterWrite_policy_limit

import org.cache2k.CacheEntry; //导入依赖的package包/类
/**
 * The configuration setting serves as a time limit.
 */
@Test
public void expireAfterWrite_policy_limit() {
  TimingHandler h = TimingHandler.of(
    CLOCK,
    Cache2kBuilder.forUnknownTypes()
      .expiryPolicy(new ExpiryPolicy() {
        @Override
        public long calculateExpiryTime(Object key, Object value, long loadTime, CacheEntry oldEntry) {
          return ETERNAL;
        }
      })
      .expireAfterWrite(5, TimeUnit.MINUTES)
      .toConfiguration()
  );
  Entry e = new Entry();
  long t = h.calculateNextRefreshTime(e, null, NOW);
  assertNotEquals(Long.MAX_VALUE, t);
  assertEquals(NOW + TimeUnit.MINUTES.toMillis(5), t);
  t = h.calculateNextRefreshTime(e, null, NOW);
  assertEquals(NOW + TimeUnit.MINUTES.toMillis(5), t);
}
 
开发者ID:cache2k,项目名称:cache2k,代码行数:25,代码来源:TimingHandlerTest.java

示例9: expireAfterWrite_policy_limit_sharp_close

import org.cache2k.CacheEntry; //导入依赖的package包/类
/**
 * Maximum expiry is limited when sharp expiry requested.
 * Corner case if expiry will happen close to requested point in time.
 */
@Test
public void expireAfterWrite_policy_limit_sharp_close() {
  long _DURATION = 100;
  final long _SHARP_POINT_IN_TIME = NOW + 5000;
  TimingHandler h = TimingHandler.of(
    CLOCK,
    Cache2kBuilder.forUnknownTypes()
      .expiryPolicy(new ExpiryPolicy() {
        @Override
        public long calculateExpiryTime(Object key, Object value, long loadTime, CacheEntry oldEntry) {
          return -_SHARP_POINT_IN_TIME;
        }
      })
      .expireAfterWrite(_DURATION, TimeUnit.MILLISECONDS)
      .toConfiguration()
  );
  Entry e = new Entry();
  long  _later = _SHARP_POINT_IN_TIME - _DURATION - 1;
  long t = h.calculateNextRefreshTime(e, null, _later);
  assertTrue("expect gap bigger then duration", HeapCache.TUNABLE.sharpExpirySafetyGapMillis > _DURATION);
  assertNotEquals(_SHARP_POINT_IN_TIME - HeapCache.TUNABLE.sharpExpirySafetyGapMillis, t);
  assertTrue(Math.abs(t) > NOW);
  assertTrue(Math.abs(t) < _SHARP_POINT_IN_TIME);
}
 
开发者ID:cache2k,项目名称:cache2k,代码行数:29,代码来源:TimingHandlerTest.java

示例10: replace

import org.cache2k.CacheEntry; //导入依赖的package包/类
@Override
public boolean replace(K key, V oldValue, V newValue) {
  checkClosed();
  checkNullValue(newValue);
  checkNullValue(oldValue);
  CacheEntry<K, V> e =
    c2kCache.replaceOrGet(
      key,
      oldValue,
      newValue,
      DUMMY_ENTRY);
  if (e != null && e != DUMMY_ENTRY) {
    touchEntry(key);
  }
  return e == null;
}
 
开发者ID:cache2k,项目名称:cache2k,代码行数:17,代码来源:TouchyJCacheAdapter.java

示例11: calculateExpiryTime

import org.cache2k.CacheEntry; //导入依赖的package包/类
@Override
public long calculateExpiryTime(K _key, V _value, long _loadTime, CacheEntry<K, V> _oldEntry) {
  if (_value == null) {
    return NO_CACHE;
  }
  Duration d;
  if (_oldEntry == null || _oldEntry.getException() != null) {
    d = policy.getExpiryForCreation();
  } else {
    d = policy.getExpiryForUpdate();
  }
  if (d == null) {
    return ExpiryTimeValues.NEUTRAL;
  }
  if (d.equals(Duration.ETERNAL)) {
    return ExpiryTimeValues.ETERNAL;
  }
  if (d.equals(Duration.ZERO)) {
    return ExpiryTimeValues.NO_CACHE;
  }
  return _loadTime + d.getTimeUnit().toMillis(d.getDurationAmount());
}
 
开发者ID:cache2k,项目名称:cache2k,代码行数:23,代码来源:TouchyJCacheAdapter.java

示例12: calculateExpiryTime

import org.cache2k.CacheEntry; //导入依赖的package包/类
@Override
public long calculateExpiryTime(final Integer key, final Object value, final long loadTime, final CacheEntry<Integer, Object> oldEntry) {
    final Long period = expirationPeriods.get(value.getClass());
    if(period != null && period > 0L) {
        return loadTime + period.longValue();
    }
    return ExpiryTimeValues.ETERNAL;
}
 
开发者ID:meraki-analytics,项目名称:orianna,代码行数:9,代码来源:InMemoryCache.java

示例13: entries

import org.cache2k.CacheEntry; //导入依赖的package包/类
@Override
public Iterable<CacheEntry<K, V>> entries() {
  return new Iterable<CacheEntry<K, V>>() {
    @Override
    public Iterator<CacheEntry<K, V>> iterator() {
      return BaseCache.this.iterator();
    }
  };
}
 
开发者ID:cache2k,项目名称:cache2k,代码行数:10,代码来源:BaseCache.java

示例14: keySet

import org.cache2k.CacheEntry; //导入依赖的package包/类
@Override
public Set<K> keySet() {
  return new AbstractSet<K>() {
    @Override
    public Iterator<K> iterator() {
      final Iterator<CacheEntry<K,V>> it = cache.entries().iterator();
      return new Iterator<K>() {

        @Override
        public boolean hasNext() {
          return it.hasNext();
        }

        @Override
        public K next() {
          return it.next().getKey();
        }

        @Override
        public void remove() {
          it.remove();
        }
      };
    }

    @Override
    public boolean contains(Object o) {
      return containsKey(o);
    }

    @Override
    public int size() {
      return ConcurrentMapWrapper.this.size();
    }
  };
}
 
开发者ID:cache2k,项目名称:cache2k,代码行数:37,代码来源:ConcurrentMapWrapper.java

示例15: values

import org.cache2k.CacheEntry; //导入依赖的package包/类
@Override
public Collection<V> values() {
  return new AbstractSet<V>() {
    @Override
    public Iterator<V> iterator() {
      final Iterator<CacheEntry<K,V>> it = cache.entries().iterator();
      return new Iterator<V>() {

        @Override
        public boolean hasNext() {
          return it.hasNext();
        }

        @Override
        public V next() {
          return it.next().getValue();
        }

        @Override
        public void remove() {
          it.remove();
        }
      };
    }

    @Override
    public int size() {
      return ConcurrentMapWrapper.this.size();
    }
  };
}
 
开发者ID:cache2k,项目名称:cache2k,代码行数:32,代码来源:ConcurrentMapWrapper.java


注:本文中的org.cache2k.CacheEntry类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。