Package org.springframework.cache.concurrent

Examples of org.springframework.cache.concurrent.ConcurrentMapCache


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

  @Test
  public void putIfAbsent() { // no transactional support for putIfAbsent
    Cache target = new ConcurrentMapCache("testCache");
    Cache cache = new TransactionAwareCacheDecorator(target);

    Object key = new Object();
    assertNull(cache.putIfAbsent(key, "123"));
    assertEquals("123", target.get(key, String.class));
    assertEquals("123", cache.putIfAbsent(key, "456").get());
    assertEquals("123", target.get(key, String.class)); // unchanged
  }
View Full Code Here


    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

  @Bean
  public CacheManager cacheManager() {
    SimpleCacheManager cacheManager = new SimpleCacheManager();

    cacheManager.setCaches(
            ImmutableList.of(new ConcurrentMapCache(USERS_CACHE))
    );

    return cacheManager;
  }
View Full Code Here

    }

    @Bean
    public CacheManager cacheManager() throws Exception {
        SimpleCacheManager scm = new SimpleCacheManager();
        Cache cache = new ConcurrentMapCache("customers");
        scm.setCaches(Arrays.asList(cache));
        return scm;
    }
View Full Code Here

class CachingConfiguration {

  @Bean
  public CacheManager cacheManager() {

    Cache cache = new ConcurrentMapCache("byUsername");

    SimpleCacheManager manager = new SimpleCacheManager();
    manager.setCaches(Arrays.asList(cache));

    return manager;
View Full Code Here

TOP

Related Classes of org.springframework.cache.concurrent.ConcurrentMapCache

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.