public IResponseBase Execute(IRequestParameter parameters) { var result = new Response <PowerReviewAvgRateResponse>(); try { _request = (PowerReviewAvgRateRequest)parameters; var cacheKey = string.Format(Config.PowerReview.CacheKeyAvgRate, _request.ProductId); result = CacheMemory.Get <Response <PowerReviewAvgRateResponse> >(cacheKey); if (result == null || result.resultset.AvgRates.Count == 0) { var communicationRequest = BuildUrl(parameters); _response = Communicate(communicationRequest); result = ParseResponse(_response); if (result.resultset.AvgRates.Count > 0) { if (Config.PowerReview.IsCacheEnabled) { CacheMemory.SetAndExpiresMinutesAsync(cacheKey, result, Config.PowerReview.Cache_TTL_InMinutes); } } } } catch (Exception ex) { _errors.Add(ex.Handle("PowerReviewGetAvgRates.Execute", ErrorSeverity.FollowUp, ErrorType.RequestError)); } return(result); }
public IResponseBase Execute(IRequestParameter parameters) { var result = new Response <AutoCompleteSearchResponse>(); try { _request = (AutocompleteSearchRequest)parameters; var cacheKey = string.Format(Config.AutocompleteSearch.CacheName, _request.SearchToken); result = CacheMemory.Get <Response <AutoCompleteSearchResponse> >(cacheKey); if (result == null || result.resultset.SearchItem.Items.Count == 0) { var communicationRequest = BuildUrl(parameters); _response = Communicate(communicationRequest); result = ParseResponse(_response); if (result.resultset.SearchItem.Items.Count > 0) { if (Config.AutocompleteSearch.IsCacheEnabled && _request.SearchToken.Length > 2) { CacheMemory.SetAndExpiresMinutesAsync(cacheKey, result, Config.AutocompleteSearch.Cache_TTL_InMin); } } } } catch (Exception) { //don't fail/performace the UI because mad search errors. //allow user to search again. return(new Response <AutoCompleteSearchResponse>()); } return(result); }
public IResponseBase Execute(IRequestParameter parameters) { var result = new Response <PowerReviewsResponse>(); try { _request = (PowerReviewsRequest)parameters; _request.Sort = (!string.IsNullOrEmpty(_request.Sort)) ? _request.Sort : "created_date desc"; var cacheKey = string.Format(Config.PowerReview.CacheKeyReviews, _request.ProductId, _request.PageNumber, _request.Sort); result = CacheMemory.Get <Response <PowerReviewsResponse> >(cacheKey); if (result == null || result.resultset.Reviews.Count == 0) { var communicationRequest = BuildUrl(parameters); _response = Communicate(communicationRequest); result = ParseResponse(_response); if (result.resultset.Reviews.Count > 0) { //per lead's request. only cache the first page if (_request.PageNumber == 0) { CacheMemory.SetAndExpiresMinutesAsync(cacheKey, result, Config.PowerReview.Cache_TTL_InMinutes); } } } } catch (Exception ex) { _errors.Add(ex.Handle("PowerReviewGetReviews.Execute", ErrorSeverity.FollowUp, ErrorType.RequestError)); } return(result); }
public InitResponse GetInitData(DateTime?forwardDate = null) { var result = new InitResponse(); result = CacheMemory.Get <InitResponse>(Config.CacheKeys.CmsInit); if (result == null || result.SessionID == null) { _homepageData = _tabletCms.GetMetaData("home_page_data"); _homepageDataProperties = (IDictionary <string, object>)_homepageData; _heroBanners = _tabletCms.GetMetaData("hero_banners"); _heroBannersDictionary = (IDictionary <string, object>)_heroBanners; try { if (!forwardDate.HasValue) { forwardDate = DateTime.Now; } } catch (Exception) { forwardDate = DateTime.Now; } result.TabletBanners = GetTabletBanners(forwardDate.Value); result.HeroBanners = GetHeroBanners(forwardDate.Value); result.ContentRows = GetContentRows(forwardDate.Value); result.FeatureImages = _mobileCms.GetImages("feature_images"); result.FeatureImagesB = _mobileCms.GetImages("feature_images_b"); result.Banners = _mobileCms.GetImages("banners"); result.CheckoutPromoMessage = GetCheckoutPromoMessage(); result.SecondaryBanners = _mobileCms.GetImages("banners-b"); var scriptToggleMetaData = _mobileCms.GetMetaData("script_toggles"); try { if (scriptToggleMetaData != null) { result.ScriptToggles = new Dictionary <string, object>(scriptToggleMetaData); } } catch (Exception) { result.ScriptToggles = new Dictionary <string, object>(); } SetPlpPromosInCache(); CacheMemory.SetAndExpiresMinutesAsync(Config.CacheKeys.CmsInit, result, 5); } return(result); }
public IResponseBase Execute(IRequestParameter parameters) { var result = new Response <SearchResponse>(); _request = (SearchRequest)parameters; try { if (_request.Href != null) { var cacheKey = string.Format(Config.CacheKeys.Search, _request.Href, _request.Page, _request.PageSize); IsViewAllProductSearch = _request.Href.Contains("view-all"); IsEmailCamPaign = _request.Href.ToLower().Contains("utm_medium=email"); result = CacheMemory.Get <Response <SearchResponse> >(cacheKey); if (result.resultset != null && string.IsNullOrWhiteSpace(result.resultset.Href)) { _hrefLookup = HrefLookup.Load(_core); var config = BuildAPIConfig(parameters); if (config != null) { result = GetResponse(config); } if (result.resultset.Filters != null && result.resultset.Filters.FilterSections != null) { result.resultset.Filters.FilterSections = SelectSpecifiedSize(result.resultset.Filters.FilterSections); } var href = ParsingHelper.GetHrefWithoutQueryString(_request.Href); result.resultset.CategoryID = _hrefLookup.Forward.Get(href); var resultVideos = CacheMemory.Get <Dictionary <string, PaylessMadCms.PromoSlot> >(Config.CacheKeys.CmsVideos); if (resultVideos != null && resultVideos.Keys.Contains(href)) { result.resultset.Promo = resultVideos[href]; } if (!_errors.Any() && result.resultset.Products.Any()) { CacheMemory.SetAndExpiresMinutesAsync(cacheKey, result, 15); } } } } catch (Exception ex) { _errors.Add(ex.Handle(string.Format("Search.Execute({0}):{1}-{2}", ex.LineNumber(), ex.Message, ex.StackTrace), ErrorSeverity.FollowUp, ErrorType.RequestError)); } return(result); }
public Dictionary <string, string> BrandImageLookup() { var result = new Dictionary <string, string>(); result = CacheMemory.Get <Dictionary <string, string> >(Config.CacheKeys.CmsBrandImages); if (result == null || result.Count == 0) { var brandImagesData = _tabletCms.GetMetaData("brand_images"); foreach (var brand in brandImagesData) { var properties = (IDictionary <string, object>)brand.Value; if (properties.ContainsKey("brand") && properties.ContainsKey("image")) { result.Add(brand.Value.brand, brand.Value.image); } } CacheMemory.SetAndExpiresMinutesAsync(Config.CacheKeys.CmsBrandImages, result, 15); } return(result); }
private void SetPlpPromosInCache() { var result = new Dictionary <string, PromoSlot>(); try { var promos = _tabletCms.GetMetaData("plp_promos"); if (promos != null) { foreach (var item in promos) { var promoSlot = new PromoSlot(); var _itemProperties = (IDictionary <string, object>)item.Value; if (_itemProperties.ContainsKey("video")) { promoSlot.VideoID = item.Value.video; } if (_itemProperties.ContainsKey("mobileImage")) { promoSlot.MobileImage = item.Value.mobileImage; } if (_itemProperties.ContainsKey("tabletImage")) { promoSlot.TabletImage = item.Value.tabletImage; } result.Add(item.Key, promoSlot); } } CacheMemory.SetAndExpiresMinutesAsync(Config.CacheKeys.CmsVideos, result, 15); } catch { } }