Package org.springframework.cache

Examples of org.springframework.cache.Cache$ValueWrapper


    assertEquals("123", target.get(key, String.class)); // unchanged
  }

  @Test
  public void evictNonTransactional() {
    Cache target = new ConcurrentMapCache("testCache");
    Cache cache = new TransactionAwareCacheDecorator(target);
    Object key = new Object();
    cache.put(key, "123");

    cache.evict(key);
    assertNull(target.get(key));
  }
View Full Code Here


    assertNull(target.get(key));
  }

  @Test
  public void evictTransactional() {
    Cache target = new ConcurrentMapCache("testCache");
    Cache cache = new TransactionAwareCacheDecorator(target);
    Object key = new Object();
    cache.put(key, "123");


    TransactionStatus status = txManager.getTransaction(new DefaultTransactionAttribute(
        TransactionDefinition.PROPAGATION_REQUIRED));
    cache.evict(key);
    assertEquals("123", target.get(key, String.class));
    txManager.commit(status);

    assertNull(target.get(key));
  }
View Full Code Here

public class GuavaCacheManagerTests {

  @Test
  public void testDynamicMode() {
    CacheManager cm = new GuavaCacheManager();
    Cache cache1 = cm.getCache("c1");
    assertTrue(cache1 instanceof GuavaCache);
    Cache cache1again = cm.getCache("c1");
    assertSame(cache1again, cache1);
    Cache cache2 = cm.getCache("c2");
    assertTrue(cache2 instanceof GuavaCache);
    Cache cache2again = cm.getCache("c2");
    assertSame(cache2again, cache2);
    Cache cache3 = cm.getCache("c3");
    assertTrue(cache3 instanceof GuavaCache);
    Cache cache3again = cm.getCache("c3");
    assertSame(cache3again, cache3);

    cache1.put("key1", "value1");
    assertEquals("value1", cache1.get("key1").get());
    cache1.put("key2", 2);
View Full Code Here

  }

  @Test
  public void testStaticMode() {
    GuavaCacheManager cm = new GuavaCacheManager("c1", "c2");
    Cache cache1 = cm.getCache("c1");
    assertTrue(cache1 instanceof GuavaCache);
    Cache cache1again = cm.getCache("c1");
    assertSame(cache1again, cache1);
    Cache cache2 = cm.getCache("c2");
    assertTrue(cache2 instanceof GuavaCache);
    Cache cache2again = cm.getCache("c2");
    assertSame(cache2again, cache2);
    Cache cache3 = cm.getCache("c3");
    assertNull(cache3);

    cache1.put("key1", "value1");
    assertEquals("value1", cache1.get("key1").get());
    cache1.put("key2", 2);
    assertEquals(2, cache1.get("key2").get());
    cache1.put("key3", null);
    assertNull(cache1.get("key3").get());
    cache1.evict("key3");
    assertNull(cache1.get("key3"));

    cm.setAllowNullValues(false);
    Cache cache1x = cm.getCache("c1");
    assertTrue(cache1x instanceof GuavaCache);
    assertTrue(cache1x != cache1);
    Cache cache2x = cm.getCache("c2");
    assertTrue(cache2x instanceof GuavaCache);
    assertTrue(cache2x != cache2);
    Cache cache3x = cm.getCache("c3");
    assertNull(cache3x);

    cache1x.put("key1", "value1");
    assertEquals("value1", cache1x.get("key1").get());
    cache1x.put("key2", 2);
    assertEquals(2, cache1x.get("key2").get());
    try {
      cache1x.put("key3", null);
      fail("Should have thrown NullPointerException");
    }
    catch (NullPointerException ex) {
      // expected
    }

    cm.setAllowNullValues(true);
    Cache cache1y = cm.getCache("c1");

    cache1y.put("key3", null);
    assertNull(cache1y.get("key3").get());
    cache1y.evict("key3");
    assertNull(cache1y.get("key3"));
  }
View Full Code Here

  }

  @Test
  public void changeCacheSpecificationRecreateCache() {
    GuavaCacheManager cm = new GuavaCacheManager("c1");
    Cache cache1 = cm.getCache("c1");

    CacheBuilder<Object, Object> cacheBuilder = CacheBuilder.newBuilder().maximumSize(10);
    cm.setCacheBuilder(cacheBuilder);
    Cache cache1x = cm.getCache("c1");
    assertTrue(cache1x != cache1);

    cm.setCacheBuilder(cacheBuilder); // Set same instance
    Cache cache1xx = cm.getCache("c1");
    assertSame(cache1x, cache1xx);
  }
View Full Code Here

  }

  @Test
  public void changeCacheLoaderRecreateCache() {
    GuavaCacheManager cm = new GuavaCacheManager("c1");
    Cache cache1 = cm.getCache("c1");

    CacheLoader<Object,Object> loader = mockCacheLoader();
    cm.setCacheLoader(loader);
    Cache cache1x = cm.getCache("c1");
    assertTrue(cache1x != cache1);

    cm.setCacheLoader(loader); // Set same instance
    Cache cache1xx = cm.getCache("c1");
    assertSame(cache1x, cache1xx);
  }
View Full Code Here

    public HazelcastCacheManager(HazelcastInstance hazelcastInstance) {
        this.hazelcastInstance = hazelcastInstance;
    }

    public Cache getCache(String name) {
        Cache cache = caches.get(name);
        if (cache == null) {
            final IMap<Object, Object> map = hazelcastInstance.getMap(name);
            cache = new HazelcastCache(map);
            final Cache currentCache = caches.putIfAbsent(name, cache);
            if (currentCache != null) {
                cache = currentCache;
            }
        }
        return cache;
View Full Code Here

   @Test
   public final void springRemoteCacheManagerShouldProperlyCreateCache() {
      final SpringRemoteCacheManager objectUnderTest = new SpringRemoteCacheManager(
               remoteCacheManager);

      final Cache defaultCache = objectUnderTest.getCache(TEST_CACHE_NAME);

      assertNotNull("getCache(" + TEST_CACHE_NAME
               + ") should have returned a default cache. However, it returned null.", defaultCache);
      assertEquals("getCache(" + TEST_CACHE_NAME + ") should have returned a cache name \""
               + TEST_CACHE_NAME + "\". However, the returned cache has a different name.",
               TEST_CACHE_NAME, defaultCache.getName());
   }
View Full Code Here

               SpringEmbeddedCacheManagerTest.class
                        .getResourceAsStream(NAMED_ASYNC_CACHE_CONFIG_LOCATION));
      final SpringEmbeddedCacheManager objectUnderTest = new SpringEmbeddedCacheManager(
               nativeCacheManager);

      final Cache cacheExpectedToHaveTheProvidedName = objectUnderTest
               .getCache(CACHE_NAME_FROM_CONFIGURATION_FILE);

      assertEquals(
               "getCache("
                        + CACHE_NAME_FROM_CONFIGURATION_FILE
                        + ") should have returned the cache having the provided name. However, the cache returned has a different name.",
               CACHE_NAME_FROM_CONFIGURATION_FILE, cacheExpectedToHaveTheProvidedName.getName());
      nativeCacheManager.stop();
   }
View Full Code Here

               nativeCacheManager);

      final org.infinispan.Cache<Object, Object> infinispanCacheAddedLater = nativeCacheManager
               .getCache(nameOfInfinispanCacheAddedLater);

      final Cache springCacheAddedLater = objectUnderTest
               .getCache(nameOfInfinispanCacheAddedLater);

      assertEquals(
               "getCache("
                        + nameOfInfinispanCacheAddedLater
                        + ") should have returned the Spring cache having the Infinispan cache added after creating "
                        + "SpringEmbeddedCacheManager as its underlying native cache. However, the underlying native cache is different.",
               infinispanCacheAddedLater, springCacheAddedLater.getNativeCache());
      nativeCacheManager.stop();
   }
View Full Code Here

TOP

Related Classes of org.springframework.cache.Cache$ValueWrapper

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.