本文整理了Java中org.ehcache.Cache.put()
方法的一些代码示例,展示了Cache.put()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Cache.put()
方法的具体详情如下:
包路径:org.ehcache.Cache
类名称:Cache
方法名:put
[英]Associates the given value to the given key in this Cache.
[中]将给定值与此缓存中的给定键相关联。
代码示例来源:origin: ehcache/ehcache3
@Override
public void doTxWork() throws Exception {
Thread.currentThread().setName("tx2");
txCache1.put(1L, "un");
txCache1.put(2L, "deux");
txCache2.put(-1L, "-un");
txCache2.put(-3L, "-trois");
}
};
代码示例来源:origin: ehcache/ehcache3
@Test
@SuppressWarnings("unchecked")
public void testSimplePutIfAbsentWithLoaderAndWriter_existsInStore() throws Exception {
testCache.put(1, "un");
reset(cacheLoaderWriter);
assertThat(testCache.putIfAbsent(1, "one"), Matchers.<CharSequence>equalTo("un"));
assertThat(testCache.get(1), Matchers.<CharSequence>equalTo("un"));
verifyZeroInteractions(cacheLoaderWriter);
}
代码示例来源:origin: ehcache/ehcache3
@Override
public void run() {
for (int i = number; i < number + 10; i++) {
cache.put(i , i);
logger.info(Thread.currentThread().getName() + " putting " + i);
}
}
}
代码示例来源:origin: ehcache/ehcache3
@Test
public void put() {
cache.put(1, "a");
changesOf(0, 0, 1, 0);
cache.put(1, "b");
changesOf(0, 0, 1, 0);
}
代码示例来源:origin: ehcache/ehcache3
@Test
public void testPutWithWriterException() throws Exception {
doThrow(new Exception("Mock Exception: cannot write 1")).when(cacheLoaderWriter).write(eq(1), eq("one"));
try {
testCache.put(1, "one");
fail("expected CacheWritingException");
} catch (CacheWritingException ex) {
// expected
}
}
代码示例来源:origin: ehcache/ehcache3
private void put(Cache<Long, String> cache, String value, boolean addToCacheRecords) {
cache.put(KEY, value);
if (addToCacheRecords) {
cacheRecords.add(new Record(KEY, cache.get(KEY)));
}
}
代码示例来源:origin: ehcache/ehcache3
@Test
public void testRemove2ArgsWithNotMatchingCacheEntry_should_not_call_writer() throws Exception {
doThrow(new Exception("Mock Exception: cannot write 1")).when(cacheLoaderWriter).delete(eq(1));
testCache.put(1, "un");
testCache.remove(1, "one");
}
代码示例来源:origin: ehcache/ehcache3
@Test
public void getEvictions() {
for (long i = 0; i < 11; i++) {
cache.put(i, "a");
}
assertThat(onHeap.getEvictions()).isEqualTo(1L);
assertStat("OnHeap:EvictionCount").isEqualTo(1L);
}
代码示例来源:origin: ehcache/ehcache3
@Test
@SuppressWarnings("unchecked")
public void testSimpleRemove2ArgsWithLoaderAndWriter_existsInStore_notEquals() throws Exception {
testCache.put(1, "un");
reset(cacheLoaderWriter);
assertThat(testCache.remove(1, "one"), is(false));
verifyZeroInteractions(cacheLoaderWriter);
}
代码示例来源:origin: ehcache/ehcache3
@Test
public void getMappings() throws Exception {
cache.put(1L, "a");
assertThat(onHeap.getMappings()).isEqualTo(1L);
assertStat("OnHeap:MappingCount").isEqualTo(1L);
}
代码示例来源:origin: ehcache/ehcache3
@Test
public void clear() {
cache.put(1, "a");
cache.put(2, "b");
changesOf(0, 0, 2, 0);
cache.clear();
changesOf(0, 0, 0, 0);
}
代码示例来源:origin: ehcache/ehcache3
@Test
public void getHits() throws Exception {
cache.put(1L, "a");
cache.get(1L);
assertThat(onHeap.getHits()).isEqualTo(1L);
assertStat("OnHeap:HitCount").isEqualTo(1L);
}
代码示例来源:origin: ehcache/ehcache3
@Test
public void removeAllKeys() {
cache.put(1, "a");
cache.put(2, "b");
changesOf(0, 0, 2, 0);
cache.removeAll(asSet(1, 2, 3));
changesOf(0, 0, 0, 2);
}
代码示例来源:origin: ehcache/ehcache3
@Test
public void getHits() {
cache.put(1L, "a");
cache.get(1L);
assertThat(onHeap.getHits()).isEqualTo(0L);
assertNoStat("OnHeap:HitCount");
}
代码示例来源:origin: ehcache/ehcache3
@Test
public void removeAllKeys() {
cache.put(1, "a");
cache.put(2, "b");
changesOf(0, 0, 2, 0);
cache.removeAll(asSet(1, 2, 3));
changesOf(0, 0, 0, 2);
}
代码示例来源:origin: ehcache/ehcache3
@Test
public void getExpirations() throws Exception {
cache.put(1L, "a");
timeSource.advanceTime(TIME_TO_EXPIRATION);
cache.get(1L);
assertThat(onHeap.getExpirations()).isEqualTo(1L);
assertStat("OnHeap:ExpirationCount").isEqualTo(1L);
}
代码示例来源:origin: ehcache/ehcache3
@Test
public void replaceKON() {
expect(cache.replace(1, "a", "b")).isFalse();
changesOf(0, 1, 0, 0);
cache.put(1, "a");
changesOf(0, 0, 1, 0);
expect(cache.replace(1, "xxx", "b")).isFalse();
changesOf(1, 0, 0, 0);
expect(cache.replace(1, "a", "b")).isTrue();
changesOf(1, 0, 1, 0);
}
代码示例来源:origin: ehcache/ehcache3
@Test
public void get() {
expect(cache.get(1)).isNull();
changesOf(0, 1, 0, 0);
cache.put(1, "a");
changesOf(0, 0, 1, 0);
expect(cache.get(1)).isEqualTo("a");
changesOf(1, 0, 0, 0);
}
代码示例来源:origin: ehcache/ehcache3
@Test
public void replaceKV() {
expect(cache.replace(1, "a")).isNull();
changesOf(0, 1, 0, 0);
cache.put(1, "a");
changesOf(0, 0, 1, 0);
expect(cache.replace(1, "b")).isEqualTo("a");
changesOf(1, 0, 1, 0);
}
代码示例来源:origin: ehcache/ehcache3
public static void testEhcache3WithSerializationAndClientClass() {
CacheManager cacheManager = CacheManagerBuilder.newCacheManagerBuilder()
.withCache("myCache", newCacheConfigurationBuilder(Long.class, Person.class, heap(10))
.add(new DefaultCopierConfiguration<>(SerializingCopier.<Person>asCopierClass(), DefaultCopierConfiguration.Type.VALUE))
.withClassLoader(TestMethods.class.getClassLoader())
.build())
.build(true);
Cache<Long, Person> myCache = cacheManager.getCache("myCache", Long.class, Person.class);
myCache.put(42L, new Person("Arthur"));
assertTrue(myCache.get(42L) instanceof Person);
}
内容来源于网络,如有侵权,请联系作者删除!