コード例 #1
0
        protected async Task EnsureDepartmentListCacheAsync()
        {
            if (_departmentListCache == null)
            {
                if (!_cache.TryGetValue(CacheKeys.EnterpriseContact_DepartmentList, out Dictionary <Guid, DepartmentListOutput> data))
                {
                    var dto = await _departmentAppService.GetAllListAsync();

                    if (dto == null || dto.Count == 0)
                    {
                        data = new Dictionary <Guid, DepartmentListOutput>();
                    }
                    else
                    {
                        data = dto.ToDictionary(o => o.Id, o => o);
                    }

                    var cacheEntryOptions = new MemoryCacheEntryOptions()
                                            .SetAbsoluteExpiration(CacheKeys.DefaultCacheAbsoluteExpiration);

                    _cache.Set(CacheKeys.EnterpriseContact_DepartmentList, data, cacheEntryOptions);
                }
                _departmentListCache = data;
            }
        }