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:grails.plugin.cache.web.filter.gemfire.GemfirePageFragmentCachingFilter.java

@Override
protected void put(Cache cache, String key, PageInfo pageInfo, Integer timeToLiveSeconds) {
    // TTL isn't supported yet
    cache.put(key, pageInfo);
}

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

@Test
public void getCacheNew_writeRead() {
    String name = "cache:ITNEW";
    Cache c = aerospikeCacheManager.getCache(name);
    c.put("B", "DEADBEEF");
    assertThat(c.get("B", String.class), is("DEADBEEF"));
    c.evict("B");
    assertThat(c.get("B"), nullValue());
}

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

@Test
public void getCacheDefault_writeRead() {
    String name = "cache:ITPRECONF";
    Cache c = aerospikeCacheManager.getCache(name);
    c.put("A", "DEADBEEF");
    assertThat(c.get("A", String.class), is("DEADBEEF"));
    c.evict("A");
    assertThat(c.get("A"), nullValue());
}

From source file:grails.plugin.cache.web.filter.redis.RedisPageFragmentCachingFilter.java

@Override
protected void put(Cache cache, String key, PageInfo pageInfo, Integer timeToLiveSeconds) {
    // just store, ttl not supported
    cache.put(key, pageInfo);
}

From source file:org.springmodules.cache.guava.GuavaCacheTest.java

@Test
public void testAllowNullValues() {
    Cache cache = new GuavaCache("name", true);
    cache.put("key", null);

    assertThat(cache.get("key").get()).isNull();
}

From source file:org.springmodules.cache.guava.GuavaCacheTest.java

@Test(expected = NullPointerException.class)
public void testDisallowNullValues() {
    Cache cache = new GuavaCache("name", false);

    cache.put("key", null);
}

From source file:springfox.documentation.spring.web.caching.CachingAspect.java

private Object cachedValue(ProceedingJoinPoint joinPoint, String cacheName, Object key) throws Throwable {
    Cache cache = this.cache.getCache(cacheName);
    if (cache.get(key) == null) {
        cache.put(key, joinPoint.proceed());
    }//from  w w  w . j  ava2  s.  c om
    return cache.get(key).get();
}

From source file:grails.plugin.cache.web.filter.simple.MemoryPageFragmentCachingFilter.java

@Override
protected void put(Cache cache, String key, PageInfo pageInfo, Integer timeToLiveSeconds) {
    // TTL isn't supported in the in-memory implementation
    cache.put(key, pageInfo);
}

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

@Test
public void testDynamicCache() throws InterruptedException {
    System.setProperty("net.sf.ehcache.skipUpdateCheck", "true");
    Cache cache1 = dynamicCacheManager1.getCache("agent_request");
    Cache cache2 = dynamicCacheManager2.getCache("agent_request");

    cache2.put("hello", "127.0.0.1");
    ThreadUtil.sleep(1000);//from w  w  w . j av  a  2 s.co m
    assertThat((String) cache1.get("hello").get(), is("127.0.0.1"));
    ThreadUtil.sleep(4000);
    assertThat(cache1.get("hello"), not(nullValue()));
    assertThat(cache2.get("hello"), not(nullValue()));
    // After timeout
    ThreadUtil.sleep(8000);
    assertThat(cache1.get("hello"), nullValue());
    assertThat(cache2.get("hello"), nullValue());
}

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

@Test
public void testDynamicCacheUpdate() throws InterruptedException {
    // Given/*from   w  w  w . ja va2  s . c  om*/
    System.setProperty("net.sf.ehcache.skipUpdateCheck", "true");
    String value = "127.0.0.1";
    Cache cache1 = dynamicCacheManager1.getCache("agent_request");
    Cache cache2 = dynamicCacheManager2.getCache("agent_request");
    cache2.put("hello", value);
    cache2.put("hello2", value);

    ThreadUtil.sleep(1000);
    // When
    assertThat((String) cache1.get("hello").get(), is(value));
    assertThat((String) cache1.get("hello2").get(), is(value));

    // Update Cache after 4 sec
    ThreadUtil.sleep(4000);
    assertThat(cache1.get("hello"), not(nullValue()));
    cache1.put("hello", value);

    // Then
    ThreadUtil.sleep(8000);
    assertThat(cache1.get("hello"), not(nullValue()));
    assertThat(cache2.get("hello"), not(nullValue()));
}