Example usage for org.springframework.cache Cache getNativeCache

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

Introduction

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

Prototype

Object getNativeCache();

Source Link

Document

Return the underlying native cache provider.

Usage

From source file:example.app.caching.provider.support.AbstractJsr107CachingProviderTests.java

@SuppressWarnings("all")
protected <T> T getNativeCache(String name) {
    Cache cache = getCache(name);
    Assert.state(cache != null, String.format("Cache [%s] not found", name));
    return (T) cache.getNativeCache();
}

From source file:org.infinispan.spring.spi.SpringEmbeddedCacheManagerTest.java

/**
 * Test method for {@link org.infinispan.spring.spi.SpringEmbeddedCacheManager#getCache(String)}.
 * @throws IOException //w  w w  .ja  v  a  2s.  c o m
 */
@Test
public final void getCacheShouldReturnACacheAddedAfterCreatingTheSpringEmbeddedCache() throws IOException {
    final String nameOfInfinispanCacheAddedLater = "infinispan.cache.addedLater";

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

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

    final Cache<Object, Object> 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();
}

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

private void updateCacheStatisticsSupports() {
    CacheManager cacheManager = appContext.getBean("cacheManager", CacheManager.class);
    boolean enableStatistics = isEnableStatistics();
    for (String cacheName : cacheManager.getCacheNames()) {
        Cache cache = cacheManager.getCache(cacheName);
        ((net.sf.ehcache.Cache) cache.getNativeCache()).setStatisticsEnabled(enableStatistics);
    }/*from   w w  w  .  j  av  a  2s  .  c  o  m*/
}

From source file:org.ngrinder.operation.cotroller.StatisticsController.java

/**
 * Get all cache statistics.<br>/*w w w.j  a  va  2  s.  c om*/
 * size is object count in memory & disk<br>
 * heap is object count in memory<br>
 * hit & miss is cache hit & miss count
 * 
 * @return Ehcache statistics list, group by cacheName
 */
private List<Map<String, Object>> getEhcacheStat() {
    List<Map<String, Object>> stats = new LinkedList<Map<String, Object>>();
    for (String cacheName : cacheManager.getCacheNames()) {
        Cache cache = cacheManager.getCache(cacheName);
        net.sf.ehcache.Cache ehcache = (net.sf.ehcache.Cache) cache.getNativeCache();
        Statistics statistics = ehcache.getStatistics();

        Map<String, Object> stat = new HashMap<String, Object>();
        stat.put("cacheName", cacheName);
        stat.put("size", statistics.getObjectCount());
        stat.put("heap", statistics.getMemoryStoreObjectCount());
        stat.put("hit", statistics.getCacheHits());
        stat.put("miss", statistics.getCacheMisses());

        stats.add(stat);
    }
    return stats;
}