spring boot整合redis,实现shiro的CacheManager

本文介绍如何在Spring Boot应用中使用Redis替代EhCache作为Shiro的CacheManager。通过分析Shiro源码,我们将实现自定义的RedisCacheManager,详细步骤包括接口实现和配置设置。
摘要由CSDN通过智能技术生成

接着上一篇博客来讲:Spring Boot整合jpa,Shiro进行权限管理

Shiro默认整合了EhCache,来实现缓存,如果我们想用redis替换EhCache来实现缓存怎么做了?我们可以从Shiro的源码来找到一些端倪。我们可以模拟EhCacheManager的实现方式,EhCacheManager类定义如下:

public class EhCacheManager implements CacheManager, Initializable, Destroyable {

}

我们从上面的代码可以看到,最终要的是实现了CacheManager接口,该接口很简单,只有一个方法:

public interface CacheManager {

    /**
     * Acquires the cache with the specified <code>name</code>.  If a cache does not yet exist with that name, a new one
     * will be created with that name and returned.
     *
     * @param name the name of the cache to a
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值