本文整理汇总了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;
}
示例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;
}
示例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;
}
示例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;
}
示例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;
}
示例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;
}
示例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"));
}
示例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));
}
示例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;<% }
示例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);
}
示例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;
}
示例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;
}
示例13: CacheableCustomerServiceImpl
import org.springframework.cache.CacheManager; //导入依赖的package包/类
public CacheableCustomerServiceImpl(CustomerRepository customerRepository,
CacheManager cacheManager,
CustomerKeyGenerator customerKeyGenerator) {
super(customerRepository);
this.cacheManager = cacheManager;
this.customerKeyGenerator = customerKeyGenerator;
}
示例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 ();
}
示例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 ();
}