配置ABP的redis

2 篇文章 0 订阅
1 篇文章 0 订阅

1. NguGet 引用 Abp.RedisCache

根据自身ABP框架版本来引用,这边我是4.9版本

 

2. 在 appsettings.json加上Redis服务器配置

"RedisCache": {

"ConnectionString": "127.0.0.1:6379",

"DatabaseId": "6"

},

 

3. 配置缓存为redis,不配置的话,走的是内存缓存

 

类的头部加入:

typeof(AbpRedisCacheModule))

 

 

PreInitialize方法中加入:

Configuration.Caching.UseRedis(option =>

{

option.ConnectionString = _appConfiguration.GetSection("RedisCache:ConnectionString").Value;

option.DatabaseId = _appConfiguration.GetValue<int>("RedisCache:DatabaseId");

});

 

 

4. 原有实体取值改造

var entity = _baseRepository.Get(id);

改成

var entity = _cacheManager.GetCache(typeof(TEntity).Name).Get(id, () => CacheGetEntity(id));

private TEntity CacheGetEntity(int id)

{

var entity = _baseRepository.Get(id);

if (entity == null) { entity = new TEntity(); }

return entity;

}

 

5. redis的启动 redis-server.exe 双击就启动啦.

redis-cli.exe 双击启动客户端,可以看见ip

 

6. 打开管理工具,清掉影响的数据

 

 

7. 启动程序访问

 

增加了两个缓存

结束:

 

 

================================

参考地址:

http://www.manongjc.com/article/76769.html

https://blog.csdn.net/weixin_30444105/article/details/97902889

==============================================

//配置所有Cache的默认过期时间为2小时 Configuration.Caching.ConfigureAll(cache => { cache.DefaultSlidingExpireTime = TimeSpan.FromHours(2); });

//配置指定的Cache过期时间为10分钟 Configuration.Caching.Configure("BossAssistant", cache => { cache.DefaultSlidingExpireTime = TimeSpan.FromMinutes(10); });

 

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值