缓存管理器

缓存管理器

Spring 3.1内置了五个缓存管理器实现,如下所示:
- SimpleCacheManager
- NoOpCacheManager
- ConcurrentMapCacheManager
- CompositeCacheManager
- EhCacheCacheManager

Spring 3.2引入了另外一个缓存管理器,这个管理器可以用在基于
JCache(JSR-107)的缓存提供商之中。除了核心的Spring框架,
Spring Data又提供了两个缓存管理器:

  • RedisCacheManager(来自于Spring Data Redis项目)
  • GemfireCacheManager(来自于Spring Data GemFire项目)

在为Spring的缓存抽象选择缓存管理器时,我们有很
多可选方案。具体选择哪一个要取决于想要使用的底层缓存供应商。
每一个方案都可以为应用提供不同风格的缓存

使用Ehcache缓存

Ehcache是最为流行的缓存供应商之一。Ehcache网站上说它是“Java领
域应用最为广泛的缓存”。鉴于它的广泛采用,Spring提供集成
Ehcache的缓存管理器是很有意义的。这个缓存管理器也就
是EhCacheCacheManager。

package com.lf.config;


import net.sf.ehcache.CacheManager;
import org.springframework.cache.annotation.EnableCaching;
import org.springframework.cache.ehcache.EhCacheCacheManager;
import org.springframework.cache.ehcache.EhCacheManagerFactoryBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.io.ClassPathResource;

/**
 * Created by LF on 2017/5/9.
 */
@Configuration
@EnableCaching
public class MyEhCacheManage {
   

    @Bean
    public EhCacheCacheManager getCaCheManage(CacheManager cm) {
        return new EhCacheCacheManager(cm);
    }

    @Bean
 
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值