public IEnumerable <ValueModel> Get() { if (!_redisCacheService.TryGetValue(key: ValuesCacheKeyTemplate.AllValuesCacheKey, result: out IEnumerable <ValueModel> values)) { values = _values;//get data from db instead _redisCacheService.Set(key: ValuesCacheKeyTemplate.AllValuesCacheKey, data: values, cacheTimeInMinutes: 1); } return(values); }
public IEnumerable <EmployeeDto> spRedisTry() { if (!_redisCacheService.TryGetValue(key: "carkey", result: out IEnumerable <EmployeeDto> values)) { values = EmployeeFactory.Create();//get data from db instead _redisCacheService.Set(key: "carkey", data: values, cacheTimeInMinutes: 60); } return(values); }
/// <summary> /// /// </summary> public async Task <IActionResult> Index() { if (!_redisCacheService.TryGetValue(key: CacheKeyTemplate.PostsCacheKey, result: out IEnumerable <PostOutput> posts)) { posts = await _postService.SearchAsync(page : 0, recordsPerPage : recordsPerPage, term : "", taxonomyId : null, taxonomyType : null, publishStatus : PublishStatus.Publish, sortOrder : SortOrder.Desc); await _redisCacheService.SetAsync(key : CacheKeyTemplate.PostsCacheKey, data : posts, cacheTimeInMinutes : 60); } return(View(posts)); }
public async Task <ActionResult> Articles(string taxonomyId = null, TaxonomyType?taxonomyType = null, string taxonomyName = "") { var cacheKey = string.Format(CacheKeyTemplate.PostsSearchCacheKey, 0, recordsPerPage, taxonomyId, taxonomyType); if (!_redisCacheService.TryGetValue(key: cacheKey, result: out IEnumerable <PostOutput> posts)) { posts = await _postService.SearchAsync(page : 0, recordsPerPage : recordsPerPage, term : "", taxonomyId : taxonomyId, taxonomyType : taxonomyType, publishStatus : PublishStatus.Publish, sortOrder : SortOrder.Desc); await _redisCacheService.SetAsync(key : cacheKey, data : posts, cacheTimeInMinutes : 60); } #region ViewBags ViewBag.TaxonomyName = taxonomyName; ViewBag.TaxonomyId = taxonomyId; ViewBag.TaxonomyType = taxonomyType; #endregion return(View(posts)); }
/// <summary> /// In memory check /// </summary> /// <param name="authId"></param> /// <param name="companyId"></param> /// <returns></returns> private async Task <bool> SpInMemoryCallToCheck(Guid authId, Guid companyId) { // "AuthIdAsKey" -> authId if (!_redisCacheService.TryGetValue(authId.ToString(), out IEnumerable <AuthCompanyDto> values)) //try get auth companies { values = await _efCoreService.FetchCompanies(authId); //cache it for 60 sec await _redisCacheService.SetAsync(authId.ToString(), values, 60); var authCachedRecord = await _redisCacheService.GetAsync <IEnumerable <AuthCompanyDto> >(authId.ToString()); authCachedRecord = authCachedRecord.Where(x => x.Id == companyId); if (!authCachedRecord.Any()) { return(false); } return(true); } else { var authCachedRecord = await _redisCacheService.GetAsync <IEnumerable <AuthCompanyDto> >(authId.ToString()); authCachedRecord = authCachedRecord.Where(x => x.Id == companyId); if (!authCachedRecord.Any()) { return(false); } return(true); } }