Package org.springframework.cache

Examples of org.springframework.cache.Cache$ValueWrapper


    assertSame(r1, service.cache(null));
  }

  public void testCacheUpdate(CacheableService<?> service) {
    Object o = new Object();
    Cache cache = cm.getCache("testCache");
    assertNull(cache.get(o));
    Object r1 = service.update(o);
    assertSame(r1, cache.get(o).get());

    o = new Object();
    assertNull(cache.get(o));
    Object r2 = service.update(o);
    assertSame(r2, cache.get(o).get());
  }
View Full Code Here


  public void testConditionalCacheUpdate(CacheableService<?> service) {
    Integer one = Integer.valueOf(1);
    Integer three = Integer.valueOf(3);

    Cache cache = cm.getCache("testCache");
    assertEquals(one, Integer.valueOf(service.conditionalUpdate(one).toString()));
    assertNull(cache.get(one));

    assertEquals(three, Integer.valueOf(service.conditionalUpdate(three).toString()));
    assertEquals(three, Integer.valueOf(cache.get(three).get().toString()));
  }
View Full Code Here

  public void testMultiCache(CacheableService<?> service) {
    Object o1 = new Object();
    Object o2 = new Object();

    Cache primary = cm.getCache("primary");
    Cache secondary = cm.getCache("secondary");

    assertNull(primary.get(o1));
    assertNull(secondary.get(o1));
    Object r1 = service.multiCache(o1);
    assertSame(r1, primary.get(o1).get());
    assertSame(r1, secondary.get(o1).get());

    Object r2 = service.multiCache(o1);
    Object r3 = service.multiCache(o1);

    assertSame(r1, r2);
    assertSame(r1, r3);

    assertNull(primary.get(o2));
    assertNull(secondary.get(o2));
    Object r4 = service.multiCache(o2);
    assertSame(r4, primary.get(o2).get());
    assertSame(r4, secondary.get(o2).get());
  }
View Full Code Here


    Object r1 = service.multiCache(o1);
    Object r2 = service.multiCache(o1);

    Cache primary = cm.getCache("primary");
    Cache secondary = cm.getCache("secondary");

    primary.put(o2, o2);
    assertSame(r1, r2);
    assertSame(r1, primary.get(o1).get());
    assertSame(r1, secondary.get(o1).get());

    service.multiEvict(o1);
    assertNull(primary.get(o1));
    assertNull(secondary.get(o1));
    assertNull(primary.get(o2));

    Object r3 = service.multiCache(o1);
    Object r4 = service.multiCache(o1);
    assertNotSame(r1, r3);
    assertSame(r3, r4);

    assertSame(r3, primary.get(o1).get());
    assertSame(r4, secondary.get(o1).get());
  }
View Full Code Here

  }

  public void testMultiPut(CacheableService<?> service) {
    Object o = Integer.valueOf(1);

    Cache primary = cm.getCache("primary");
    Cache secondary = cm.getCache("secondary");

    assertNull(primary.get(o));
    assertNull(secondary.get(o));
    Object r1 = service.multiUpdate(o);
    assertSame(r1, primary.get(o).get());
    assertSame(r1, secondary.get(o).get());

    o = Integer.valueOf(2);
    assertNull(primary.get(o));
    assertNull(secondary.get(o));
    Object r2 = service.multiUpdate(o);
    assertSame(r2, primary.get(o).get());
    assertSame(r2, secondary.get(o).get());
  }
View Full Code Here

  }

  public void testPutRefersToResult(CacheableService<?> service) throws Exception {
    Long id = Long.MIN_VALUE;
    TestEntity entity = new TestEntity();
    Cache primary = cm.getCache("primary");
    assertNull(primary.get(id));
    assertNull(entity.getId());
    service.putRefersToResult(entity);
    assertSame(entity, primary.get(id).get());
  }
View Full Code Here

  }

  public void testMultiCacheAndEvict(CacheableService<?> service) {
    String methodName = "multiCacheAndEvict";

    Cache primary = cm.getCache("primary");
    Cache secondary = cm.getCache("secondary");
    Object key = Integer.valueOf(1);

    secondary.put(key, key);

    assertNull(secondary.get(methodName));
    assertSame(key, secondary.get(key).get());

    Object r1 = service.multiCacheAndEvict(key);
    assertSame(r1, service.multiCacheAndEvict(key));

    // assert the method name is used
    assertSame(r1, primary.get(methodName).get());
    assertNull(secondary.get(methodName));
    assertNull(secondary.get(key));
  }
View Full Code Here

    assertNull(secondary.get(methodName));
    assertNull(secondary.get(key));
  }

  public void testMultiConditionalCacheAndEvict(CacheableService<?> service) {
    Cache primary = cm.getCache("primary");
    Cache secondary = cm.getCache("secondary");
    Object key = Integer.valueOf(1);

    secondary.put(key, key);

    assertNull(primary.get(key));
    assertSame(key, secondary.get(key).get());

    Object r1 = service.multiConditionalCacheAndEvict(key);
    Object r3 = service.multiConditionalCacheAndEvict(key);

    assertTrue(!r1.equals(r3));
    assertNull(primary.get(key));

    Object key2 = Integer.valueOf(3);
    Object r2 = service.multiConditionalCacheAndEvict(key2);
    assertSame(r2, service.multiConditionalCacheAndEvict(key2));

    // assert the method name is used
    assertSame(r2, primary.get(key2).get());
    assertNull(secondary.get(key2));
  }
View Full Code Here

  @Test
  public void testCustomKeyGenerator() {
    Object param = new Object();
    Object r1 = cs.customKeyGenerator(param);
    assertSame(r1, cs.customKeyGenerator(param));
    Cache cache = cm.getCache("testCache");
    // Checks that the custom keyGenerator was used
    Object expectedKey = SomeCustomKeyGenerator.generateKey("customKeyGenerator", param);
    assertNotNull(cache.get(expectedKey));
  }
View Full Code Here

    CacheManager customCm = ctx.getBean("customCacheManager", CacheManager.class);
    Object key = new Object();
    Object r1 = cs.customCacheManager(key);
    assertSame(r1, cs.customCacheManager(key));

    Cache cache = customCm.getCache("testCache");
    assertNotNull(cache.get(key));
  }
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.