Meowv / Blog

🤣本项目有不同开发版本,最新版底层基于 abp vNext 搭建和免费开源跨平台框架 .NET5 进行开发,使用 MongoDB 存储数据,Redis 缓存数据。项目采用前后端分离的模式进行开发,API 遵循 RESTful 接口规范,页面使用 Blazor 进行开发,可作为 .NET Core 入门项目进行学习。If you liked `Blog` project or if it helped you, please give a star ⭐️ for this repository. 👍👍👍
https://meowv.com
MIT License
1.28k stars 281 forks source link

关于缓存的开启与停用时,Application层的机制是如何规避缓存 #17

Closed SamuelLiDR closed 3 years ago

SamuelLiDR commented 3 years ago
 "Caching": {
    "IsOpen": true,
    "RedisConnectionString": "127.0.0.1:6379,defaultDatabase=0,poolsize=50,ssl=false,writeBuffer=10240,ConnectTimeout=15000,SyncTimeout=5000"
  }

你好,关于这里的 IsOpen,如果设置为false;按照你的写法就是停用了Redis,那么在 .Application中如下:

       /// <summary>
        /// 获取分类名称
        /// </summary>
        /// <param name="name"></param>
        /// <returns></returns>
        public async Task<ServiceResult<string>> GetCategoryAsync(string name)
        {
            return await _blogCacheService.GetCategoryAsync(name, async () =>
            {
                var result = new ServiceResult<string>();

                var category = await _categoryRepository.FindAsync(x => x.DisplayName.Equals(name));
                if (null == category)
                {
                    result.IsFailed(ResponseText.WHAT_NOT_EXIST.FormatWith("分类", name));
                    return result;
                }

                result.IsSuccess(category.CategoryName);
                return result;
            });
        }

_blogCacheService.GetCategoryAsync 是会自动规避调用Redis吗?是怎样规避的,能告知一下原理?

Meowv commented 3 years ago

https://github.com/Meowv/Blog/blob/master/src/Meowv.Blog.Application.Caching/MeowvBlogApplicationCachingModule.cs#L23

在模块启动的时候已经关闭了。