Beispiel #1
0
        private async Task <MappingData> EnsureLoadMappingData()
        {
            if (!_cache.TryGetValue(CacheKeys.Common_EmployeeList, out MappingData data))
            {
                data = new MappingData();
                var dto = await _employeeAppService.GetCacheDataAsync();

                if (dto?.Count > 0)
                {
                    data.List = dto;

                    foreach (var item in dto)
                    {
                        if (!string.IsNullOrEmpty(item.Number))
                        {
                            data.ByNumber[item.Number] = item;
                        }

                        if (item.UserId.HasValue)
                        {
                            data.ByUserId[item.UserId.Value] = item;
                        }

                        data.ById[item.Id] = item;
                    }
                }

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

                _cache.Set(CacheKeys.EnterpriseContact_PositionList, data, cacheEntryOptions);
            }
            return(data);
        }