示例#1
0
 private IEnumerable <FaqItemDto> GetAllCached()
 {
     return(CacheProvider.GetOrAdd("FaqService.GetAll",
                                   CacheTagUtilities.Merge(CacheTags.FaqItem),
                                   TimeSpan.FromMinutes(60),
                                   () => GetAll()));
 }
示例#2
0
 private void GetOrAdd()
 {
     CacheProvider.GetOrAdd(
         CustomerKey,
         () => new Customer {
         CustomerId = 1
     },
         configurator => configurator.SetAbsoluteExpiration(Expiration));
 }
        private Dictionary <string, List <CategoryPage> > GetCategoryMap(DataScopeIdentifier scope, CultureInfo cultureInfo)
        {
            var cacheKey = new CacheKey(CacheConfigurationCategoryNames.CategoryUrls, $"map_{scope.Name}", cultureInfo);

            return(CacheProvider.GetOrAdd(cacheKey, () =>
            {
                using (new DataConnection(scope.ToPublicationScope(), cultureInfo))
                {
                    return DataFacade.GetData <CategoryPage>()
                    .GroupBy(_ => _.CategoryId)
                    .ToDictionary(_ => _.Key, _ => _.ToList());
                }
            }));
        }
        public string BuildCategoryBrowsingUrl(BuildCategoryBrowsingUrlParam param)
        {
            var websiteId = WebsiteContext.WebsiteId;
            var scope     = DataScopeManager.CurrentDataScope;

            var key = $"{websiteId}{param.CategoryId}{param.IsAllProductsPage}{scope}";

            var cacheKey = new CacheKey(CacheConfigurationCategoryNames.CategoryUrls, key, param.CultureInfo);

            var categoryBaseUrl = CacheProvider.GetOrAdd(cacheKey, () =>
            {
                // Because of ConfigureAwait(false), we lost context here.
                // Therefore we need to re-initialize C1 context because getting the Url.
                using (ThreadDataManager.EnsureInitialize())
                {
                    var map = GetCategoryMap(scope, param.CultureInfo);

                    if (!map.TryGetValue(param.CategoryId, out var categoryPages))
                    {
                        return(null);
                    }

                    foreach (var categoryPage in categoryPages.Where(_ => _.IsAllProductsPage == param.IsAllProductsPage))
                    {
                        if (HasAncestor(categoryPage.PageId, websiteId))
                        {
                            return(PageService.GetPageUrl(categoryPage.PageId, param.CultureInfo));
                        }
                    }
                }

                return(null);
            });

            // Category page is not found
            if (categoryBaseUrl == null)
            {
                return(null);
            }

            var finalUrl = UrlFormatter.AppendQueryString(categoryBaseUrl, BuildSearchQueryString(new BuildSearchUrlParam
            {
                SearchCriteria = param.Criteria
            }));

            return(finalUrl);
        }
        public string BuildCategoryBrowsingUrl(BuildCategoryBrowsingUrlParam param)
        {
            var itemId   = GuidUtility.Create(GetNamespace(param.IsAllProductsPage), param.CategoryId);
            var cacheKey = new CacheKey(CacheConfigurationCategoryNames.CategoryUrls, itemId.ToString(), param.CultureInfo);

            var categoryBaseUrl = CacheProvider.GetOrAdd(cacheKey, () => GetPageUrl(itemId, param.CultureInfo));

            // Category page is not found
            if (categoryBaseUrl == null)
            {
                return(null);
            }

            var finalUrl = UrlFormatter.AppendQueryString(categoryBaseUrl, BuildSearchQueryString(new BuildSearchUrlParam
            {
                SearchCriteria = param.Criteria
            }));

            return(finalUrl);
        }