当前位置: 首页>>代码示例>>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;未经允许,请勿转载。