Java Code Examples for org.springframework.cache.ehcache.EhCacheCacheManager

The following examples show how to use org.springframework.cache.ehcache.EhCacheCacheManager. These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
private CacheManager decision(org.springframework.cache.CacheManager springCacheManager) {
	if (springCacheManager instanceof EhCacheCacheManager) {
		EhCacheManager ehCacheManager = new EhCacheManager();
		ehCacheManager.setCacheManager(((EhCacheCacheManager) springCacheManager).getCacheManager());
		return ehCacheManager;
	}
	
	if (springCacheManager instanceof org.springframework.data.redis.cache.RedisCacheManager) {
		GenericJackson2JsonRedisSerializer jsonSerializer = new GenericJackson2JsonRedisSerializer();
		RedisTemplate rt = new RedisTemplate<Object, Object>();
		rt.setConnectionFactory(SpringContextUtils.getBean(RedisConnectionFactory.class));
		rt.setKeySerializer(jsonSerializer);
		rt.setHashKeySerializer(jsonSerializer);
		rt.setBeanClassLoader(this.getClass().getClassLoader());
		rt.afterPropertiesSet();
		RedisCacheManager redisCacheManager = new RedisCacheManager();
		redisCacheManager.setRedisTemplate(rt);
		return redisCacheManager;
	}
	return new SpringCacheManager(springCacheManager);
}
 
Example 2
private void biuldCacheManager() {
	
	this.cacheManager = this.customizer.getCacheManager();
	if(Objects.isNull(this.cacheManager)) {
		if(Objects.isNull(springCacheManager)) {
			this.cacheManager = new MapCacheManager();
		}else {
			if (springCacheManager instanceof EhCacheCacheManager) {
				EhCacheManager ehCacheManager = new EhCacheManager();
				ehCacheManager.setCacheManager(((EhCacheCacheManager) springCacheManager).getCacheManager());
				this.cacheManager = ehCacheManager;
			}
			if (springCacheManager instanceof org.springframework.data.redis.cache.RedisCacheManager) {
				RedisCacheManager redisCacheManager = new RedisCacheManager();
				redisCacheManager.setRedisTemplate(RedisUtils.imitateRedisTemplate());
				this.cacheManager = redisCacheManager;
			}
		}
	}
	this.cacheDelegator = new CacheDelegator(this.cacheManager);
}
 
Example 3
@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;
}
 
Example 4
Source Project: ServiceCutter   Source File: CacheConfiguration.java    License: Apache License 2.0 6 votes vote down vote up
@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;
}
 
Example 5
Source Project: Project   Source File: CachingConfig3.java    License: Apache License 2.0 5 votes vote down vote up
@Bean
public CacheManager cacheManager(net.sf.ehcache.CacheManager cm, 
		RedisTemplate<String, Object> redisTemplate) {
	
	CompositeCacheManager compositeCacheManager = new CompositeCacheManager();
	List<CacheManager> managers = new ArrayList<CacheManager>();
	managers.add(new EhCacheCacheManager(cm));
	managers.add(new RedisCacheManager(redisTemplate));
	compositeCacheManager.setCacheManagers(managers);//添加缓存管理器,按添加顺序查找,没找到再往下找
	return compositeCacheManager;
}
 
Example 6
Source Project: chronus   Source File: Ehcache.java    License: Apache License 2.0 4 votes vote down vote up
public Ehcache(EhCacheCacheManager ehCacheCacheManager) {
    this.ehCacheCacheManager = ehCacheCacheManager;
}
 
Example 7
Source Project: Project   Source File: CachingConfig.java    License: Apache License 2.0 4 votes vote down vote up
@Bean
public EhCacheCacheManager cacheManager(CacheManager cm) {
	return new EhCacheCacheManager(cm);
}
 
Example 8
@Bean
public CacheManager cacheManager() {
	return new EhCacheCacheManager(cacheManagerFactoryBean().getObject());
}
 
Example 9
Source Project: api-layer   Source File: CacheConfig.java    License: Eclipse Public License 2.0 4 votes vote down vote up
@Bean
public CacheManager cacheManager() {
    return new EhCacheCacheManager(ehCacheCacheManager().getObject());
}
 
Example 10
Source Project: MicroCommunity   Source File: CacheConfiguration.java    License: Apache License 2.0 4 votes vote down vote up
@Bean(name = "appEhCacheCacheManager")
public EhCacheCacheManager ehCacheCacheManager(EhCacheManagerFactoryBean bean){
    return new EhCacheCacheManager (bean.getObject());
}
 
Example 11
Source Project: Spring-5.0-Cookbook   Source File: SpringDispatcherConfig.java    License: MIT License 4 votes vote down vote up
@Bean
public CacheManager cacheManager(){
	CacheManager cm = new EhCacheCacheManager( ehCacheCacheManager().getObject());
	return cm;
}
 
Example 12
@Bean
public CacheManager cacheManager() {
    val manager = new EhCacheCacheManager();
    manager.setCacheManager(ehcache().getObject());
    return manager;
}
 
Example 13
Source Project: Spring-Boot-Blog   Source File: CacheConfiguration.java    License: MIT License 4 votes vote down vote up
@Bean
public EhCacheCacheManager ehCacheCacheManager(){
    return new EhCacheCacheManager(ehCacheManagerFactoryBean().getObject());
}
 
Example 14
Source Project: yes-cart   Source File: HibernateEhCacheRegionFactory.java    License: Apache License 2.0 4 votes vote down vote up
/**
 * Spring IoC.
 *
 * @param cacheManager cache manager
 */
public void setCacheManager(final EhCacheCacheManager cacheManager) {
    PROVIDER = new SingletonEhCacheRegionFactory(null) {{
        manager = cacheManager.getCacheManager();
    }};
}
 
Example 15
Source Project: herd   Source File: DaoSpringModuleConfig.java    License: Apache License 2.0 4 votes vote down vote up
@Bean
@Override
public CacheManager cacheManager()
{
    return new EhCacheCacheManager(ehCacheManager());
}
 
Example 16
Source Project: kvf-admin   Source File: EhCacheConfig.java    License: MIT License 2 votes vote down vote up
/**
 * ehcache 主要的管理器
 *
 * @param cacheManagerFactoryBean cm
 * @return ec
 */
@Bean
public EhCacheCacheManager ehCacheCacheManager(EhCacheManagerFactoryBean cacheManagerFactoryBean) {
    return new EhCacheCacheManager(cacheManagerFactoryBean.getObject());
}
 
Example 17
Source Project: cc-s   Source File: CacheConfig.java    License: MIT License 2 votes vote down vote up
/**
 *  ehcache管理器
 * @param bean
 * @return
 */
@Bean
public EhCacheCacheManager ehCacheCacheManager(EhCacheManagerFactoryBean bean){
    return new EhCacheCacheManager(bean.getObject());
}