當前位置: 首頁>>代碼示例>>Java>>正文


Java CacheManager類代碼示例

本文整理匯總了Java中org.springframework.cache.CacheManager的典型用法代碼示例。如果您正苦於以下問題:Java CacheManager類的具體用法?Java CacheManager怎麽用?Java CacheManager使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


CacheManager類屬於org.springframework.cache包,在下文中一共展示了CacheManager類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: stats

import org.springframework.cache.CacheManager; //導入依賴的package包/類
@Primary
@Bean(name = "stats")
public CacheManager stats(RedisTemplate redisTemplate) {
    RedisCacheManager cacheManager = new RedisCacheManager(redisTemplate);
    cacheManager.setUsePrefix(true);
    cacheManager.setDefaultExpiration(TWENTY_MINS_SECS);
    return cacheManager;
}
 
開發者ID:celestial-winter,項目名稱:vics,代碼行數:9,代碼來源:CacheConfig.java

示例2: cacheManager

import org.springframework.cache.CacheManager; //導入依賴的package包/類
@Bean
public CacheManager cacheManager() {
    log.debug("Starting Ehcache");
    cacheManager = net.sf.ehcache.CacheManager.create();
    cacheManager.getConfiguration().setMaxBytesLocalHeap(env.getProperty("cache.ehcache.maxBytesLocalHeap", String.class, "16M"));
    log.debug("Registering Ehcache Metrics gauges");
    Set<EntityType<?>> entities = entityManager.getMetamodel().getEntities();
    for (EntityType<?> entity : entities) {

        String name = entity.getName();
        if (name == null || entity.getJavaType() != null) {
            name = entity.getJavaType().getName();
        }
        Assert.notNull(name, "entity cannot exist without a identifier");

        net.sf.ehcache.Cache cache = cacheManager.getCache(name);
        if (cache != null) {
            cache.getCacheConfiguration().setTimeToLiveSeconds(env.getProperty("cache.timeToLiveSeconds", Long.class, 3600L));
            net.sf.ehcache.Ehcache decoratedCache = InstrumentedEhcache.instrument(metricRegistry, cache);
            cacheManager.replaceCacheWithDecoratedCache(cache, decoratedCache);
        }
    }
    EhCacheCacheManager ehCacheManager = new EhCacheCacheManager();
    ehCacheManager.setCacheManager(cacheManager);
    return ehCacheManager;
}
 
開發者ID:VHAINNOVATIONS,項目名稱:BCDS,代碼行數:27,代碼來源:CacheConfiguration.java

示例3: cacheManager

import org.springframework.cache.CacheManager; //導入依賴的package包/類
@Bean
public CacheManager cacheManager(JHipsterProperties jHipsterProperties) {
    log.debug("Starting Ehcache");
    cacheManager = net.sf.ehcache.CacheManager.create();
    cacheManager.getConfiguration().setMaxBytesLocalHeap(jHipsterProperties.getCache().getEhcache().getMaxBytesLocalHeap());
    log.debug("Registering Ehcache Metrics gauges");
    Set<EntityType<?>> entities = entityManager.getMetamodel().getEntities();
    for (EntityType<?> entity : entities) {

        String name = entity.getName();
        if (name == null || entity.getJavaType() != null) {
            name = entity.getJavaType().getName();
        }
        Assert.notNull(name, "entity cannot exist without a identifier");

        net.sf.ehcache.Cache cache = cacheManager.getCache(name);
        if (cache != null) {
            cache.getCacheConfiguration().setTimeToLiveSeconds(jHipsterProperties.getCache().getTimeToLiveSeconds());
            net.sf.ehcache.Ehcache decoratedCache = InstrumentedEhcache.instrument(metricRegistry, cache);
            cacheManager.replaceCacheWithDecoratedCache(cache, decoratedCache);
        }
    }
    EhCacheCacheManager ehCacheManager = new EhCacheCacheManager();
    ehCacheManager.setCacheManager(cacheManager);
    return ehCacheManager;
}
 
開發者ID:GastonMauroDiaz,項目名稱:buenojo,代碼行數:27,代碼來源:CacheConfiguration.java

示例4: cacheManager

import org.springframework.cache.CacheManager; //導入依賴的package包/類
@SuppressWarnings("rawtypes")
@Bean
public CacheManager cacheManager(RedisTemplate redisTemplate) {
    RedisCacheManager rcm = new RedisCacheManager(redisTemplate);
    //設置緩存過期時間
    //rcm.setDefaultExpiration(60);//秒
    return rcm;
}
 
開發者ID:ChinaLHR,項目名稱:JavaQuarkBBS,代碼行數:9,代碼來源:RedisConfig.java

示例5: cacheManager

import org.springframework.cache.CacheManager; //導入依賴的package包/類
@Bean
public CacheManager cacheManager() {
    log.debug("Creating Guava cache manager");
    CacheBuilder<Object, Object> thirtyMinuteBuilder = CacheBuilder.newBuilder().expireAfterAccess(30, TimeUnit.MINUTES).recordStats();
    CacheBuilder<Object, Object> oneHourBuilder = CacheBuilder.newBuilder().expireAfterAccess(1, TimeUnit.HOURS).recordStats();
    CacheBuilder<Object, Object> threeHoursBuilder = CacheBuilder.newBuilder().expireAfterAccess(3, TimeUnit.HOURS).recordStats();

    Map<String, CacheBuilder<Object, Object>> builderMap = new LinkedHashMap<>();
    builderMap.put("schedule", oneHourBuilder);
    builderMap.put("team", threeHoursBuilder);
    builderMap.put("roster", threeHoursBuilder);
    builderMap.put("results", thirtyMinuteBuilder);
    builderMap.put("legacyPlayer", threeHoursBuilder);
    builderMap.put("player", threeHoursBuilder);
    builderMap.put("banList", threeHoursBuilder);
    builderMap.put("transactions", thirtyMinuteBuilder);
    builderMap.put("overwatch", threeHoursBuilder);

    GuavaCacheManager guavaCacheManager = new GuavaCacheManager() {
        @Override
        protected com.google.common.cache.Cache<Object, Object> createNativeGuavaCache(String name) {
            CacheBuilder<Object, Object> builder = builderMap.get(name);
            if (builder != null) {
                log.debug("Creating cache for {}: {}", name, builder.toString());
                return builder.build();
            }
            log.debug("Creating fallback cache for {}", name);
            return super.createNativeGuavaCache(name);
        }
    };
    guavaCacheManager.setCacheBuilder(thirtyMinuteBuilder);
    return guavaCacheManager;
}
 
開發者ID:quanticc,項目名稱:sentry,代碼行數:34,代碼來源:CacheConfiguration.java

示例6: cacheManager

import org.springframework.cache.CacheManager; //導入依賴的package包/類
@Bean
public CacheManager cacheManager ( RedisTemplate redisTemplate ) {
	RedisCacheManager redisCacheManager = new RedisCacheManager( redisTemplate );
	// 默認30分鍾
	redisCacheManager.setDefaultExpiration( defaultExpiration );
	redisCacheManager.setExpires( expires );
	redisCacheManager.setUsePrefix( usePrefix );
	return redisCacheManager;
}
 
開發者ID:yujunhao8831,項目名稱:spring-boot-start-current,代碼行數:10,代碼來源:SpringCacheConfig.java

示例7: testDynamicMode

import org.springframework.cache.CacheManager; //導入依賴的package包/類
@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);
	assertEquals(2, cache1.get("key2").get());
	cache1.put("key3", null);
	assertNull(cache1.get("key3").get());
	cache1.evict("key3");
	assertNull(cache1.get("key3"));
}
 
開發者ID:langtianya,項目名稱:spring4-understanding,代碼行數:26,代碼來源:GuavaCacheManagerTests.java

示例8: cacheManager

import org.springframework.cache.CacheManager; //導入依賴的package包/類
@Bean
public CacheManager cacheManager(@Autowired Config config) {
    long ttl = Long.valueOf(config.getProperties().getProperty(Config.PROP_CACHE_TTL));

    double pctOfHeap = Double.valueOf(config.getProperties().getProperty(Config.PROP_CACHE_SIZE));
    long cacheSizeMB = new Double(Runtime.getRuntime().maxMemory() * pctOfHeap / 1048576.0).longValue();

    LogFactory.getLog(getClass()).info(
            String.format("Initializing cache TTL=%d secs, size=%d MB (%.2f percent of max heap)",
                    ttl, cacheSizeMB, pctOfHeap * 100));

    org.ehcache.config.CacheConfiguration<Object, Object> cacheConfiguration = CacheConfigurationBuilder
            .newCacheConfigurationBuilder(Object.class, Object.class,
                    ResourcePoolsBuilder.newResourcePoolsBuilder()
                            .heap(cacheSizeMB, MemoryUnit.MB))
            .withExpiry(Expirations.timeToLiveExpiration(new org.ehcache.expiry.Duration(ttl, TimeUnit.SECONDS)))
            .build();

    Map<String, CacheConfiguration<?, ?>> caches = new HashMap<>();
    caches.put(CACHE_DEFAULT, cacheConfiguration);

    EhcacheCachingProvider provider = (EhcacheCachingProvider) javax.cache.Caching.getCachingProvider();

    // when our cacheManager bean is re-created several times for
    // diff test configurations, this provider seems to hang on to state
    // causing cache settings to not be right. so we always close().
    provider.close();

    DefaultConfiguration configuration = new DefaultConfiguration(
            caches, provider.getDefaultClassLoader());

    return new JCacheCacheManager(
            provider.getCacheManager(provider.getDefaultURI(), configuration));
}
 
開發者ID:codeforkjeff,項目名稱:conciliator,代碼行數:35,代碼來源:Application.java

示例9: if

import org.springframework.cache.CacheManager; //導入依賴的package包/類
@Bean<% if (hibernateCache == 'ehcache') { %>
public CacheManager cacheManager(JHipsterProperties jHipsterProperties) {
    log.debug("Starting Ehcache");
    cacheManager = net.sf.ehcache.CacheManager.create();
    cacheManager.getConfiguration().setMaxBytesLocalHeap(jHipsterProperties.getCache().getEhcache().getMaxBytesLocalHeap());
    log.debug("Registering Ehcache Metrics gauges");<% if (databaseType == 'sql') { %>
    Set<EntityType<?>> entities = entityManager.getMetamodel().getEntities();
    for (EntityType<?> entity : entities) {

        String name = entity.getName();
        if (name == null || entity.getJavaType() != null) {
            name = entity.getJavaType().getName();
        }
        Assert.notNull(name, "entity cannot exist without a identifier");

        net.sf.ehcache.Cache cache = cacheManager.getCache(name);
        if (cache != null) {
            cache.getCacheConfiguration().setTimeToLiveSeconds(jHipsterProperties.getCache().getTimeToLiveSeconds());
            net.sf.ehcache.Ehcache decoratedCache = InstrumentedEhcache.instrument(metricRegistry, cache);
            cacheManager.replaceCacheWithDecoratedCache(cache, decoratedCache);
        }
    }<% } %>
    EhCacheCacheManager ehCacheManager = new EhCacheCacheManager();
    ehCacheManager.setCacheManager(cacheManager);
    return ehCacheManager;<% }
 
開發者ID:xetys,項目名稱:jhipster-ribbon-hystrix,代碼行數:26,代碼來源:_CacheConfiguration.java

示例10: setUp

import org.springframework.cache.CacheManager; //導入依賴的package包/類
@Before
   public void setUp() throws Exception {
annotationUtils = new AnnotationUtils();
searchQueryUtils = new SearchQueryUtils();
template = mock(ElasticsearchTemplate.class);
client = mock(Client.class);
when(template.getClient()).thenReturn(client);
textSearchService = mock(TextSearchService.class);
mixedCache = mock(Cache.class);
cacheManager = mock(CacheManager.class);
when(cacheManager.getCache(anyString())).thenReturn(mixedCache);
when(mixedCache.get(queryString)).thenReturn(null);
Map map = new HashMap();
mixedCache.put(queryStringWithPage, map);
//when(mixedCache.get(queryStringWithPage)).thenReturn(new ValueWrapper())
impl = new W3CSearchServiceImpl(annotationUtils, template, textSearchService, cacheManager);
   }
 
開發者ID:dlcs,項目名稱:the-mathmos-server,代碼行數:18,代碼來源:W3CSearchServiceImpTest.java

示例11: getCacheStatistics

import org.springframework.cache.CacheManager; //導入依賴的package包/類
@Override
public CacheStatistics getCacheStatistics(final CacheManager cacheManager, final RedissonCache cache) {
    final DefaultCacheStatistics defaultCacheStatistics = new DefaultCacheStatistics();
    defaultCacheStatistics.setSize((long) cache.getNativeCache().size());
    defaultCacheStatistics.setGetCacheCounts(cache.getCacheHits(), cache.getCacheMisses());
    return defaultCacheStatistics;
}
 
開發者ID:qq1588518,項目名稱:JRediClients,代碼行數:8,代碼來源:RedissonCacheStatisticsProvider.java

示例12: redisCacheManager

import org.springframework.cache.CacheManager; //導入依賴的package包/類
@Bean
@Qualifier("redisTemplate")
public CacheManager redisCacheManager(RedisTemplate<Serializable, Serializable> redisTemplate) {
    RedisCacheManager cacheManager = new RedisCacheManager(redisTemplate);
    cacheManager.setTransactionAware(true);
    cacheManager.setDefaultExpiration(PropertiesUtil.getInt("redis.expiration", 10));
    return cacheManager;
}
 
開發者ID:iBase4J,項目名稱:iBase4J-Common,代碼行數:9,代碼來源:JedisConfig.java

示例13: CacheableCustomerServiceImpl

import org.springframework.cache.CacheManager; //導入依賴的package包/類
public CacheableCustomerServiceImpl(CustomerRepository customerRepository,
                                    CacheManager cacheManager,
                                    CustomerKeyGenerator customerKeyGenerator) {

    super(customerRepository);
    this.cacheManager = cacheManager;
    this.customerKeyGenerator = customerKeyGenerator;
}
 
開發者ID:fdlessard,項目名稱:SpringBootLogExecutionTime,代碼行數:9,代碼來源:CacheableCustomerServiceImpl.java

示例14: setUp

import org.springframework.cache.CacheManager; //導入依賴的package包/類
@BeforeClass
public void setUp ()
{
   this.userService = ApplicationContextProvider.getBean (
         fr.gael.dhus.service.UserService.class);
   this.cacheManager =
         ApplicationContextProvider.getBean (CacheManager.class);
   authenticate ();
}
 
開發者ID:SentinelDataHub,項目名稱:dhus-core,代碼行數:10,代碼來源:TestCacheUserService.java

示例15: setUp

import org.springframework.cache.CacheManager; //導入依賴的package包/類
@BeforeClass
public void setUp ()
{
   this.extPoint = ApplicationContextProvider.getBean (SolrReplicationExtensionPoint.class);
   this.extPoint.setSearchService(new SearchServiceForTest());

   this.cacheManager = ApplicationContextProvider.getBean (CacheManager.class);
   this.userService = ApplicationContextProvider.getBean (UserService.class);
   this.userDao = ApplicationContextProvider.getBean (UserDao.class);
   this.productService = ApplicationContextProvider.getBean (ProductService.class);
   this.productDao = ApplicationContextProvider.getBean (ProductDao.class);
   authenticate ();

   productService.count ();
}
 
開發者ID:SentinelDataHub,項目名稱:dhus-core,代碼行數:16,代碼來源:TestCacheSymDS.java


注:本文中的org.springframework.cache.CacheManager類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。