本文整理汇总了Java中org.cache2k.Cache类的典型用法代码示例。如果您正苦于以下问题:Java Cache类的具体用法?Java Cache怎么用?Java Cache使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
Cache类属于org.cache2k包,在下文中一共展示了Cache类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。
示例1: initial_GetYieldsNull
import org.cache2k.Cache; //导入依赖的package包/类
@Test
public void initial_GetYieldsNull() {
Cache<Integer, Integer> c = target.cache();
final AtomicBoolean _reached = new AtomicBoolean(false);
EntryProcessor p = new EntryProcessor() {
@Override
public Object process(MutableCacheEntry e) throws Exception {
assertNull(e.getValue());
_reached.set(true);
return null;
}
};
final int _KEY = 123;
Object _result = c.invoke(_KEY, p);
assertNull(_result);
assertTrue("no exception during process", _reached.get());
assertFalse(c.containsKey(_KEY));
}
开发者ID:cache2k,项目名称:cache2k,代码行数:19,代码来源:EntryProcessorTest.java
示例2: testWithCacheAndKeyObject
import org.cache2k.Cache; //导入依赖的package包/类
/**
* Work with cache key object and one big cache.
*/
@Test
public void testWithCacheAndKeyObject() {
Cache<CacheKey, String> c =
Cache2kBuilder.of(CacheKey.class, String.class)
.eternal(true)
.loader(new CacheLoader<CacheKey, String>() {
@Override
public String load(CacheKey o) {
DateFormat df = DateFormat.getDateInstance(o.format, o.locale);
return df.format(o.date);
}
})
.build();
PrintWriter w = new PrintWriter(new CharArrayWriter());
List<Date> l = provideListWith3MillionDates();
for (Date d : l) {
w.print(c.get(new CacheKey(Locale.FRANCE, DateFormat.LONG, d)));
}
c.close();
}
开发者ID:cache2k,项目名称:cache2k-benchmark,代码行数:24,代码来源:DateFormattingBenchmark.java
示例3: testDisabled
import org.cache2k.Cache; //导入依赖的package包/类
@Test
public void testDisabled() throws Exception {
String _name = getClass().getName() + ".testInitialProperties";
Cache c = new Cache2kBuilder<Long, List<Collection<Long>>> () {}
.name(_name)
.disableStatistics(true)
.eternal(true)
.build();
objectName = constructCacheObjectName(_name);
try {
retrieve("Alert");
fail("exception expected");
} catch (InstanceNotFoundException ex) {
}
c.close();
}
开发者ID:cache2k,项目名称:cache2k,代码行数:17,代码来源:JmxSupportTest.java
示例4: setException_propagation
import org.cache2k.Cache; //导入依赖的package包/类
@Test
public void setException_propagation() {
final String _TEXT = "set inside process";
Cache<Integer, Integer> c = target.cache(new CacheRule.Specialization<Integer, Integer>() {
@Override
public void extend(final Cache2kBuilder<Integer, Integer> b) {
b.retryInterval(Long.MAX_VALUE, TimeUnit.MILLISECONDS);
}
});
c.invoke(KEY, new EntryProcessor<Integer, Integer, Object>() {
@Override
public Object process(final MutableCacheEntry<Integer, Integer> e) throws Exception {
e.setException(new IllegalStateException(_TEXT));
return null;
}
});
try {
c.get(KEY);
fail();
} catch (CacheLoaderException ex) {
assertTrue(ex.getCause().toString().contains(_TEXT));
}
}
开发者ID:cache2k,项目名称:cache2k,代码行数:24,代码来源:EntryProcessorTest.java
示例5: testGetWithSource
import org.cache2k.Cache; //导入依赖的package包/类
public void testGetWithSource() {
CacheLoader<String,Integer> _lengthCountingSource = new CacheLoader<String, Integer>() {
@Override
public Integer load(String o) {
return o.length();
}
};
Cache<String,Integer> c =
Cache2kBuilder.of(String.class, Integer.class)
.loader(_lengthCountingSource)
.eternal(true)
.build();
int v = c.get("hallo");
v = c.get("long string");
c.close();
}
开发者ID:cache2k,项目名称:cache2k,代码行数:17,代码来源:BasicCacheTest.java
示例6: testEventPackage
import org.cache2k.Cache; //导入依赖的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
示例7: maximizeConcurrency
import org.cache2k.Cache; //导入依赖的package包/类
/**
* Check that the maximize concurrency is routed through to the timing handler properly.
*/
@Test
public void maximizeConcurrency() {
Cache<Integer, Integer> c = Cache2kBuilder.of(Integer.class, Integer.class)
.boostConcurrency(true)
.expireAfterWrite(5, TimeUnit.MINUTES)
.loader(new CacheLoader<Integer, Integer>() {
@Override
public Integer load(final Integer key) throws Exception {
return key + 123;
}
})
.build();
int _timerMask =
((TimingHandler.Static) c.requestInterface(HeapCache.class).timing).timerMask;
if (Runtime.getRuntime().availableProcessors() >1) {
assertTrue(_timerMask > 0);
}
c.close();
}
开发者ID:cache2k,项目名称:cache2k,代码行数:23,代码来源:TimingHandlerTest.java
示例8: purgeCalled
import org.cache2k.Cache; //导入依赖的package包/类
@Test @Ignore("purgeCalled: move to slow tests")
public void purgeCalled() {
int _SIZE = 1000;
int _PURGE_INTERVAL = TunableFactory.get(TimingHandler.Tunable.class).purgeInterval;
Cache<Integer, Integer> c = Cache2kBuilder.of(Integer.class, Integer.class)
.entryCapacity(_SIZE)
.expireAfterWrite(5, TimeUnit.MINUTES)
.loader(new CacheLoader<Integer, Integer>() {
@Override
public Integer load(final Integer key) throws Exception {
return key + 123;
}
})
.build();
for (int i = 0; i < _PURGE_INTERVAL + _SIZE + 125; i++) {
c.get(i);
}
assertEquals(10000, _PURGE_INTERVAL);
int _timerCacnelCount =
((TimingHandler.Static) c.requestInterface(HeapCache.class).timing).timerCancelCount;
assertTrue("purge called", _timerCacnelCount < _PURGE_INTERVAL);
c.close();
}
开发者ID:cache2k,项目名称:cache2k,代码行数:24,代码来源:TimingHandlerTest.java
示例9: testFunctionalLoader
import org.cache2k.Cache; //导入依赖的package包/类
@Test
public void testFunctionalLoader() {
Cache<Integer,Integer> c = target.cache(new CacheRule.Specialization<Integer, Integer>() {
@Override
public void extend(final Cache2kBuilder<Integer, Integer> b) {
b.loader(new FunctionalCacheLoader<Integer, Integer>() {
@Override
public Integer load(final Integer key) throws Exception {
return key * 7;
}
});
}
});
int v = c.get(1);
assertEquals(7, v);
}
开发者ID:cache2k,项目名称:cache2k,代码行数:17,代码来源:CacheLoaderTest.java
示例10: testGetWithSource
import org.cache2k.Cache; //导入依赖的package包/类
@Test
public void testGetWithSource() {
CacheLoader<String,Integer> _lengthCountingSource = new CacheLoader<String, Integer>() {
@Override
public Integer load(String o) {
return o.length();
}
};
Cache<String,Integer> c =
Cache2kBuilder.of(String.class, Integer.class)
.loader(_lengthCountingSource)
.eternal(true)
.build();
int v = c.get("hallo");
assertEquals(5, v);
v = c.get("long string");
assertEquals(11, v);
c.close();
}
开发者ID:cache2k,项目名称:cache2k,代码行数:20,代码来源:CacheTest.java
示例11: testLoadAll
import org.cache2k.Cache; //导入依赖的package包/类
@Test
public void testLoadAll() throws Exception {
final AtomicInteger _countLoad = new AtomicInteger();
Cache<Integer,Integer> c = target.cache(new CacheRule.Specialization<Integer, Integer>() {
@Override
public void extend(final Cache2kBuilder<Integer, Integer> b) {
b .loader(new CacheLoader<Integer, Integer>() {
@Override
public Integer load(final Integer key) throws Exception {
return _countLoad.incrementAndGet();
}
});
}
});
c.get(5);
CompletionWaiter w = new CompletionWaiter();
c.loadAll(toIterable(5, 6), w);
w.awaitCompletion();
assertEquals(2, _countLoad.get());
assertEquals((Integer) 2, c.get(6));
c.loadAll(toIterable(5, 6), null);
c.loadAll(Collections.EMPTY_SET, null);
}
开发者ID:cache2k,项目名称:cache2k,代码行数:24,代码来源:CacheLoaderTest.java
示例12: invokeAll_exception
import org.cache2k.Cache; //导入依赖的package包/类
@Test
public void invokeAll_exception() {
Cache<Integer, Integer> c = target.cache();
Map<Integer, EntryProcessingResult<Object>> _resultMap = c.invokeAll(toIterable(KEY), new EntryProcessor<Integer, Integer, Object>() {
@Override
public Object process(final MutableCacheEntry<Integer, Integer> e) throws Exception {
throw new IllegalStateException("test");
}
});
assertEquals(1, _resultMap.size());
EntryProcessingResult<Object> _result = _resultMap.get(KEY);
assertNotNull(_result);
assertNotNull(_result.getException());
assertEquals(IllegalStateException.class, _result.getException().getClass());
try {
_result.getResult();
fail();
} catch (EntryProcessingException ex ) {
assertEquals(IllegalStateException.class, ex.getCause().getClass());
}
}
开发者ID:cache2k,项目名称:cache2k,代码行数:22,代码来源:EntryProcessorTest.java
示例13: customExecutor
import org.cache2k.Cache; //导入依赖的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
示例14: testAdvancedLoader
import org.cache2k.Cache; //导入依赖的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
示例15: testBigCacheTimingWithUpdate
import org.cache2k.Cache; //导入依赖的package包/类
@Test
public void testBigCacheTimingWithUpdate() {
final int _CACHE_SIZE = 1000000;
Cache<Integer,Integer> c =
Cache2kBuilder.of(Integer.class, Integer.class)
.entryCapacity(_CACHE_SIZE)
.eternal(true)
.build();
for (int i = 0; i < _CACHE_SIZE; i++) {
c.put(i, i);
}
for (int i = 0; i < _CACHE_SIZE; i++) {
c.put(i, i);
}
assertNotNull(c.toString());
}
开发者ID:cache2k,项目名称:cache2k,代码行数:17,代码来源:BasicTimingTest.java
示例16: testEvictCold
import org.cache2k.Cache; //导入依赖的package包/类
@Test
public void testEvictCold() {
final int _SIZE = 30;
Cache<Integer, Integer> c =
Cache2kBuilder.of(Integer.class, Integer.class)
.eternal(true)
.entryCapacity(_SIZE)
.build();
for (int i = 0; i < _SIZE / 2; i++) {
c.put(i, i);
}
for (int i = 0; i < _SIZE / 2; i++) {
c.put(i, i);
}
for (int i = 0; i < _SIZE * 2; i++) {
c.put(i, i);
}
int _count = 0;
for (int k : c.keys()) {
_count++;
}
assertEquals(_SIZE, _count);
c.close();
}
开发者ID:cache2k,项目名称:cache2k,代码行数:25,代码来源:EvictionTest.java
示例17: duplicateCacheName
import org.cache2k.Cache; //导入依赖的package包/类
@Test
public void duplicateCacheName() {
String _managerName = getClass().getName() + ".duplicateCacheName";
Log.registerSuppression(CacheManager.class.getName() + ":" + _managerName, new Log.SuppressionCounter());
CacheManager mgr = CacheManager.getInstance(_managerName);
try {
Cache c0 = Cache2kBuilder.forUnknownTypes()
.manager(mgr)
.eternal(true)
.name(this.getClass(), "same")
.build();
Cache c1 = Cache2kBuilder.forUnknownTypes()
.manager(mgr)
.eternal(true)
.name(this.getClass(), "same")
.build();
fail("exception expected");
} catch (IllegalArgumentException ex) {
}
mgr.close();
}
开发者ID:cache2k,项目名称:cache2k,代码行数:23,代码来源:Cache2kBuilderTest.java
示例18: cacheClosedEventFired
import org.cache2k.Cache; //导入依赖的package包/类
private void cacheClosedEventFired(boolean _wiredCache) {
final AtomicBoolean _FIRED = new AtomicBoolean();
Cache2kBuilder _builder = Cache2kBuilder.forUnknownTypes();
_builder.addCacheClosedListener(new CacheClosedListener() {
@Override
public void onCacheClosed(final Cache cache) {
_FIRED.set(true);
}
});
if (_wiredCache) {
StaticUtil.enforceWiredCache(_builder);
}
Cache c = _builder.build();
c.close();
assertTrue(_FIRED.get());
}
开发者ID:cache2k,项目名称:cache2k,代码行数:17,代码来源:Cache2kBuilderTest.java
示例19: preHandle
import org.cache2k.Cache; //导入依赖的package包/类
@Override
public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws
Exception {
if (!(handler instanceof HandlerMethod)) {
return true;
}
String token = request.getHeader(requestHeaderProperties.getUserToken());
if (null != token) {
LoginUser loginUser = null;
Cache<String, LoginUser> localUserCache = (Cache<String, LoginUser>) ACU.bean("localUserCache");
String localUserCacheKey = loginUserService.getClass().getCanonicalName() + ":" + token;
if (null != localUserCache && localUserCache.containsKey(localUserCacheKey)) {
loginUser = localUserCache.get(localUserCacheKey);
if (loginUser.getTokenExpireTime().isBefore(LocalDateTime.now())) {
localUserCache.remove(localUserCacheKey);
loginUser = null;
}
}
if (null == loginUser) {
loginUser = loginUserService.getUserByToken(token);
if (null != loginUser) {
if (loginUser.getTokenExpireTime().isBefore(LocalDateTime.now())) {
loginUser = null;
} else {
if (null != localUserCache) {
localUserCache.put(localUserCacheKey, loginUser);
}
}
}
}
if (null != loginUser) {
requestAttributes.setLoginUser(loginUser);
}
}
return true;
}
开发者ID:superkoh,项目名称:k-framework,代码行数:37,代码来源:UserInterceptor.java
示例20: localUserCache
import org.cache2k.Cache; //导入依赖的package包/类
@Bean("localUserCache")
Cache<String, LoginUser> localUserCache() {
return new Cache2kBuilder<String, LoginUser>() {
}
.name("localUserCache")
.expireAfterWrite(expire, TimeUnit.SECONDS)
.entryCapacity(capacity)
.build();
}
开发者ID:superkoh,项目名称:k-framework,代码行数:10,代码来源:LocalUserCacheAutoConfig.java
注:本文中的org.cache2k.Cache类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论