Example usage for org.springframework.cache Cache put

List of usage examples for org.springframework.cache Cache put

Introduction

In this page you can find the example usage for org.springframework.cache Cache put.

Prototype

void put(Object key, @Nullable Object value);

Source Link

Document

Associate the specified value with the specified key in this cache.

Usage

From source file:us.swcraft.springframework.cache.aerospike.usage.AerospikeCacheManagerFastSerializeIT.java

@Test
public void getCacheNew_writeRead() {
    String name = "cache:ITNEW";
    Cache c = aerospikeCacheManager.getCache(name);
    String id = UUID.randomUUID().toString();
    c.put(id, "DEADBEEF");
    assertThat(c.get(id, String.class), is("DEADBEEF"));
    c.evict(id);/* www.j  a v  a  2  s. c  om*/
    assertThat(c.get(id), nullValue());
    System.out.print(false);
}

From source file:org.ngrinder.infra.config.DynamicCacheManagerBigCacheCloneTest.java

@Test
public void testDynamicCache() throws InterruptedException {
    dynamicCacheManagerConfig1 = new ReloadableDynamicCacheManager(40001, "cache1");
    config = mock(Config.class);
    dynamicCacheManagerConfig1.setConfig(config);
    currentIp = NetworkUtil.getLocalHostAddress();
    when(config.getClusterURIs()).thenReturn(new String[] { currentIp + ":40001", currentIp + ":40002" });
    when(config.getCurrentIP()).thenReturn(currentIp);
    when(config.isCluster()).thenReturn(true);
    dynamicCacheManager1 = dynamicCacheManagerConfig1.dynamicCacheManager();
    dynamicCacheManager1.afterPropertiesSet();
    Cache cache = dynamicCacheManager1.getCache("agent_request");
    for (int i = 0; i < 100; i++) {
        cache.put("Hello" + i, i);
    }//from   w  w w .ja  v  a2s .c o  m
    dynamicCacheManagerConfig2 = new ReloadableDynamicCacheManager(40002, "cache2");
    when(config.getClusterURIs()).thenReturn(new String[] { currentIp + ":40001", currentIp + ":40002" });
    dynamicCacheManagerConfig2.setConfig(config);
    dynamicCacheManager2 = dynamicCacheManagerConfig2.dynamicCacheManager();
    dynamicCacheManager2.afterPropertiesSet();
    ThreadUtil.sleep(3000);
    assertThat(((Ehcache) (dynamicCacheManager2.getCache("agent_request").getNativeCache())).getKeys().size(),
            is(100));
}

From source file:net.eusashead.spring.gaecache.GaeCacheManagerITCase.java

@Test
public void testLazyCreatedCache() throws Exception {

    // This cache is not pre-configured
    Cache lazy = cacheManager.getCache("other");
    Assert.assertNotNull(lazy);//from   w w w .j  a  v  a2  s . c o m

    // Cache something
    Foo foo = new Foo(new FooKey(1l), "bar");
    lazy.put(GaeCacheKey.create("bar"), foo);

    // Check consistency
    assertCached(ms, foo, "other", "bar");
}

From source file:net.eusashead.spring.gaecache.GaeCacheITCase.java

@Test
public void testCacheNullResult() throws Exception {

    // Create a cache
    Cache cache = new GaeCache("nullCache");

    // Cache a null value
    cache.put(GaeCacheKey.create(null), null);

    // Check consistency
    assertCached(ms, null, "nullCache", new Object[0]);

}

From source file:com.baidu.rigel.biplatform.tesseract.datasource.impl.DataSourcePoolServiceImpl.java

@Override
public void initDataSourceInfo(DataSourceInfo dataSourceInfo) throws DataSourceException {
    Cache dsInfoCache = storeManager.getDataStore(DATASOURCEINFO_POOL_CACHE_NAME);
    // ???cache?????
    dsInfoCache.put(dataSourceInfo.getDataSourceKey(), dataSourceInfo);
    // ?????????//from w w w . ja  va  2  s. c o m

}

From source file:us.swcraft.springframework.cache.aerospike.config.annotation.EnableAerospikeCacheManagerKryoReflectionIT.java

@Test
public void storeObject_noDefaultConstructor() {
    String name = "ITPRECONF";
    Cache c = cacheManager.getCache(name);
    assertThat(c, notNullValue());//from  ww  w  .j a v a2 s.c  o m

    StoredNoDefaultConstructor s = new StoredNoDefaultConstructor("ID", "NAME");
    c.put("NDC", s);
    StoredNoDefaultConstructor result = c.get("NDC", StoredNoDefaultConstructor.class);
    assertThat(result, notNullValue());
    assertThat(result.getId(), is("ID"));
    assertThat(result.getName(), is("NAME"));
}

From source file:us.swcraft.springframework.cache.aerospike.config.annotation.EnableAerospikeCacheManagerKryoIT.java

@Test
public void storeObject_notImplementingSerializable() {
    String name = "ITPRECONF";
    Cache c = cacheManager.getCache(name);
    assertThat(c, notNullValue());/*from www  .  j a  v a 2  s.c  om*/

    StoredNotSerializable s = new StoredNotSerializable();
    s.setId("ID");
    s.setName("NAME");
    c.put("NS", s);
    StoredNotSerializable result = c.get("NS", StoredNotSerializable.class);
    assertThat(result, notNullValue());
    assertThat(result.getId(), is("ID"));
    assertThat(result.getName(), is("NAME"));
}

From source file:com.baidu.rigel.biplatform.tesseract.meta.impl.MetaDataServiceImpl.java

@Override
public void cacheCube(Cube cube) {
    if (cube == null) {
        throw new IllegalArgumentException("cube is null");
    }/*from w  w w  . ja v a  2 s.com*/
    Cache cache = storeManager.getDataStore(CUBE_CACHE_NAME);

    cache.put(cube.getId(), cube);
    // ??cache?IDcube

}

From source file:net.eusashead.spring.gaecache.GaeCacheManagerITCase.java

@Test
public void testCacheManager() throws Exception {
    Cache cache = cacheManager.getCache("default");

    // Check cache is empty
    Assert.assertNotNull(cache);//from ww  w  . j ava 2  s. c  om
    GaeCacheKey cacheKey = GaeCacheKey.create("key");
    Assert.assertNull(cache.get(cacheKey));

    // Put something in the cache
    cache.put(cacheKey, "foo");
    Assert.assertEquals(new SimpleValueWrapper("foo").get(), cache.get(cacheKey).get());

    // Check consistency
    Assert.assertNotNull(cache.get(cacheKey));
}

From source file:net.eusashead.spring.gaecache.GaeCacheITCase.java

@Test
public void testCacheNullKey() throws Exception {

    // Create a cache
    Cache cache = new GaeCache("nullCache");

    // Cache a null value
    Foo foo = new Foo(new FooKey(1l), "null");
    GaeCacheKey cacheKey = GaeCacheKey.create(null);
    cache.put(cacheKey, foo);

    // Check cached value
    Assert.assertNotNull(cache.get(cacheKey));
    Assert.assertNotNull(cache.get(cacheKey).get());
    Assert.assertEquals(foo, cache.get(cacheKey).get());

}