public List <ProductCategory> GetProductCategoriesByStoreIdFromCache(int storeId, string type) { String key = String.Format("GetProductCategoriesByStoreIdFromCache-{0}-{1}", storeId, type); List <ProductCategory> items = null; ProductCategoryCache.TryGet(key, out items); if (items == null) { var cats = this.FindBy(r => r.StoreId == storeId && r.CategoryType.Equals(type, StringComparison.InvariantCultureIgnoreCase)) .OrderBy(r => r.Ordering) .Include(r => r.Products.Select(r1 => r1.ProductFiles.Select(m => m.FileManager))); items = cats.ToList(); foreach (var category in items) { foreach (var ccc in category.Products) { ccc.Description = ""; // GeneralHelper.GetDescription(ccc.Description, 200); } } ProductCategoryCache.Set(key, items, MemoryCacheHelper.CacheAbsoluteExpirationPolicy(ProjectAppSettings.GetWebConfigInt("ProductCategories_CacheAbsoluteExpiration_Minute", 10))); } return(items); }
public async Task <ActionResult> Brands() { var sitemapItems = new List <SitemapItem>(); String key = String.Format("BrandsSiteMap-{0}", StoreId); ProductSitemapItemCache.TryGet(key, out sitemapItems); if (sitemapItems == null) { sitemapItems = new List <SitemapItem>(); var brandsTask = BrandService.GetBrandsAsync(StoreId, null, true); await Task.WhenAll(brandsTask); var brands = brandsTask.Result; foreach (var brand in brands) { var brandDetailLink = LinkHelper.GetBrandIdRouteValue(brand); var siteMap = new SitemapItem(Url.AbsoluteAction("detail", "brands", new { id = brandDetailLink }), changeFrequency: SitemapChangeFrequency.Monthly, priority: 1.0); sitemapItems.Add(siteMap); } ProductSitemapItemCache.Set(key, sitemapItems, MemoryCacheHelper.CacheAbsoluteExpirationPolicy(ProjectAppSettings.CacheLongSeconds)); } return(new SitemapResult(sitemapItems)); }
public ActionResult Products() { var sitemapItems = new List <SitemapItem>(); String key = String.Format("ProductSitemapItemCache-{0}", StoreId); ProductSitemapItemCache.TryGet(key, out sitemapItems); if (sitemapItems == null) { sitemapItems = new List <SitemapItem>(); var products = ProductRepository.GetProductByTypeAndCategoryIdFromCache(StoreId, StoreConstants.ProductType, -1); var categories = ProductCategoryService.GetProductCategoriesByStoreIdFromCache(StoreId, StoreConstants.ProductType); foreach (var product in products) { var cat = categories.FirstOrDefault(r => r.Id == product.ProductCategoryId); if (cat != null) { var productDetailLink = LinkHelper.GetProductIdRouteValue(product, cat.Name); var siteMap = new SitemapItem(Url.AbsoluteAction("Product", "Products", new { id = productDetailLink }), changeFrequency: SitemapChangeFrequency.Monthly, priority: 1.0); sitemapItems.Add(siteMap); } } ProductSitemapItemCache.Set(key, sitemapItems, MemoryCacheHelper.CacheAbsoluteExpirationPolicy(ProjectAppSettings.CacheLongSeconds)); } return(new SitemapResult(sitemapItems)); }
public Store GetStore(String domainName) { String key = String.Format("GetStoreDomain-{0}", domainName); Store site = null; StoreCache.TryGet(key, out site); if (site == null) { site = this.GetStoreByDomain(domainName); if (site != null) { string layout = String.Format("~/Views/Shared/Layouts/{0}.cshtml", !String.IsNullOrEmpty((String)site.Layout) ? (String)site.Layout : "_Layout1"); var isFileExist = File.Exists(System.Web.HttpContext.Current.Server.MapPath(layout)); _defaultlayout = String.Format(_defaultlayout, ProjectAppSettings.GetWebConfigString("DefaultLayout", "_Layout1")); if (!isFileExist) { Logger.Info(String.Format("Layout is not found.Default Layout {0} is used.Site Domain is {1} ", _defaultlayout, site.Domain)); } String selectedLayout = isFileExist ? layout : _defaultlayout; site.Layout = selectedLayout; StoreCache.Set(key, site, MemoryCacheHelper.CacheAbsoluteExpirationPolicy(ProjectAppSettings.GetWebConfigInt("TooMuchTime_CacheAbsoluteExpiration_Minute", 100000))); } } return(site); }
public String GetPostJsonFromCacheOrWebservice(string baseUrl, string apiAddress, string json) { String url = String.Format("Post:{0}/{1}", baseUrl, apiAddress); String returnJson = String.Empty; if (RequestHelperCache.TryGet(url, out returnJson)) { Logger.Info(String.Format("Return Categories From Cache {0}", url)); return(returnJson); } else { var response = MakeJsonPost(baseUrl, apiAddress, json); if (response.StatusCode == HttpStatusCode.OK) { returnJson = response.Content; // if (IsCacheEnable) { RequestHelperCache.Set(url, returnJson, MemoryCacheHelper.CacheAbsoluteExpirationPolicy(_cacheMinute)); } } Logger.Trace(String.Format("Return Categories From Webservise {0}", url)); } return(returnJson); }
public ActionResult AdminSearch(String adminsearchkey, int page = 1) { if (String.IsNullOrEmpty(adminsearchkey)) { return(View(new PagedList <BaseEntity>(new List <BaseEntity>(), page - 1, 20, 0))); } ViewBag.SearchKey = adminsearchkey; adminsearchkey = adminsearchkey.Trim().ToLower(); int storeId = this.LoginStore.Id; String key = String.Format("SearchEntireStore-{0}-{1}", storeId, adminsearchkey); List <BaseEntity> resultList = null; StoreSearchCache.TryGet(key, out resultList); if (resultList == null) { resultList = SearchEntireStoreAsync(adminsearchkey, storeId).Result; StoreSearchCache.Set(key, resultList, MemoryCacheHelper.CacheAbsoluteExpirationPolicy(ProjectAppSettings.GetWebConfigInt("SearchEntireStore_Minute", 10))); } var returnSearchModel = new PagedList <BaseEntity>(resultList, page - 1, 20, resultList.Count); return(View(returnSearchModel)); }
public StorePagedList <Content> GetContentsCategoryId(int storeId, int?categoryId, string typeName, bool?isActive, int page, int pageSize) { String key = String.Format("Store-{0}-GetContentsCategoryId-{1}-{2}-{3}-{4}-{5}", storeId, typeName, categoryId, isActive.HasValue ? isActive.Value.ToStr() : "", page, pageSize); StorePagedList <Content> items = null; _contentCacheStorePagedList.IsCacheEnable = this.IsCacheEnable; _contentCacheStorePagedList.TryGet(key, out items); if (items == null) { var returnList = this.GetAllIncluding(r => r.ContentFiles.Select(r1 => r1.FileManager)) .Where(r2 => r2.StoreId == storeId && r2.Type.Equals(typeName, StringComparison.InvariantCultureIgnoreCase)); if (categoryId.HasValue) { returnList = returnList.Where(r => r.CategoryId == categoryId.Value); } if (isActive.HasValue) { returnList = returnList.Where(r => r.State == isActive); } var cat = returnList.OrderByDescending(r => r.Id).ToList(); items = new StorePagedList <Content>(cat.Skip((page - 1) * pageSize).Take(pageSize).ToList(), page, pageSize, cat.Count()); // items = new PagedList<Content>(cat, page, cat.Count()); // items = (PagedList<Content>) cat.ToPagedList(page, pageSize); _contentCacheStorePagedList.Set(key, items, MemoryCacheHelper.CacheAbsoluteExpirationPolicy(this.CacheMinute)); } return(items); }
public List <FileManager> GetFilesByStoreIdFromCache(int storeId) { String key = String.Format("StoreFileManager-{0}", storeId); List <FileManager> items = null; StoreFileManagerCache.TryGet(key, out items); if (items == null) { items = GetFilesByStoreId(storeId); StoreFileManagerCache.Set(key, items, MemoryCacheHelper.CacheAbsoluteExpirationPolicy(ProjectAppSettings.GetWebConfigInt("FileManager_CacheAbsoluteExpiration_Minute", 10))); } return(items); }
public List <Store> GetAllStores() { String key = String.Format("GetAllStores"); List <Store> sites = null; AllStoreCache.TryGet(key, out sites); if (sites == null) { sites = GetAll().ToList(); StoreCache.Set(key, sites, MemoryCacheHelper.CacheAbsoluteExpirationPolicy(ProjectAppSettings.GetWebConfigInt("TooMuchTime_CacheAbsoluteExpiration_Minute", 100000))); } return(sites); }
public StorePagedList <FileManager> GetImagesByStoreId(int storeId, int page, int pageSize) { String key = String.Format("StoreFileManager-{0}", storeId); StorePagedList <FileManager> items = null; StorePagedListFileManagerCache.TryGet(key, out items); if (items == null) { var images = FindBy(r => r.StoreId == storeId).ToList(); items = new StorePagedList <FileManager>(images.Skip((page - 1) * pageSize).Take(pageSize).ToList(), page, pageSize, images.Count()); StorePagedListFileManagerCache.Set(key, items, MemoryCacheHelper.CacheAbsoluteExpirationPolicy(ProjectAppSettings.GetWebConfigInt("FileManager_CacheAbsoluteExpiration_Minute", 10))); } return(items); }
public List <Navigation> GetStoreActiveNavigations(int storeId) { String key = String.Format("Navigation-{0}", storeId); List <Navigation> items = null; NavigationsCache.TryGet(key, out items); if (items == null) { items = GetStoreNavigations(storeId).Where(r => r.State).ToList(); NavigationsCache.Set(key, items, MemoryCacheHelper.CacheAbsoluteExpirationPolicy(ProjectAppSettings.GetWebConfigInt("MainMenuNavigation_CacheAbsoluteExpiration_Minute", 10))); } return(items); }
public List <Product> GetProductByTypeAndCategoryIdFromCache(int storeId, string typeName, int categoryId) { String key = String.Format("GetProductByTypeAndCategoryIdFromCache-{0}-{1}-{2}", storeId, typeName, categoryId); List <Product> items = null; ProductCache.TryGet(key, out items); if (items == null) { items = GetProductByTypeAndCategoryId(storeId, typeName, categoryId); ProductCache.Set(key, items, MemoryCacheHelper.CacheAbsoluteExpirationPolicy(ProjectAppSettings.GetWebConfigInt("Products_CacheAbsoluteExpiration_Minute", 10))); } return(items); }
public static string RenderPartialToStringCache(this Controller controller, string partialView, ViewDataDictionary viewData) { String key = String.Format("RenderPartialToStringCache-{0}", partialView); String item = null; PartialViewToStringCache.TryGet(key, out item); if (String.IsNullOrEmpty(item)) { item = RenderPartialToString(controller, partialView, viewData, new TempDataDictionary()); PartialViewToStringCache.Set(key, item, MemoryCacheHelper.CacheAbsoluteExpirationPolicy(ProjectAppSettings.CacheLongSeconds)); } return(item); }
public List <Setting> GetStoreSettingsFromCache(int storeid) { String key = String.Format("GetStoreSettingsFromCache-{0}", storeid); _settingStoreCache.IsCacheEnable = this.IsCacheEnable; List <Setting> items = null; _settingStoreCache.TryGet(key, out items); if (items == null) { items = GetStoreSettings(storeid).Where(r => r.State).OrderBy(r => r.Ordering).ToList(); _settingStoreCache.Set(key, items, MemoryCacheHelper.CacheAbsoluteExpirationPolicy(ProjectAppSettings.GetWebConfigInt("Setting_CacheAbsoluteExpiration_Minute", 10))); } return(items); }
public Store GetStore(int id) { String key = String.Format("GetStore-{0}", id); Store site = null; StoreCache.TryGet(key, out site); if (site == null) { site = GetSingle(id); if (site != null) { StoreCache.Set(key, site, MemoryCacheHelper.CacheAbsoluteExpirationPolicy(ProjectAppSettings.GetWebConfigInt("TooMuchTime_CacheAbsoluteExpiration_Minute", 100000))); } } return(site); }
protected List <FileManager> GetStoreImages() { String key = String.Format("GetStoreImages-{0}", StoreId); _settingStoreCache.IsCacheEnable = true; List <FileManager> items = null; _imagesStoreCache.TryGet(key, out items); if (items == null) { var itemsAsyn = FileManagerService.GetImagesByStoreId(StoreId, true); _imagesStoreCache.Set(key, itemsAsyn, MemoryCacheHelper.CacheAbsoluteExpirationPolicy(ProjectAppSettings.CacheLongSeconds)); } return(items); }
protected List<Setting> GetStoreSettings() { String key = String.Format("GetStoreSettingsFromCacheAsync-{0}", StoreId); _settingStoreCache.IsCacheEnable = true; List<Setting> items = null; _settingStoreCache.TryGet(key, out items); if (items == null) { var itemsAsyn = SettingService.GetStoreSettingsFromCache(StoreId); items = itemsAsyn; _settingStoreCache.Set(key, items, MemoryCacheHelper.CacheAbsoluteExpirationPolicy(ProjectAppSettings.GetWebConfigInt("Setting_CacheAbsoluteExpiration_Minute", 10))); } return items; }
public StoreUser GetStoreUserByUserId(int userId) { String key = String.Format("GetStoreUserByUserId-{0}", userId); StoreUser item = null; StoreUserCache.TryGet(key, out item); if (item == null) { item = this.FindBy(r => r.UserId == userId).FirstOrDefault(); // item = this.GetSingleIncluding(userId, r => r.UserProfile); //var res = from s in this.StoreDbContext.StoreUsers // join u in this.StoreDbContext.UserProfiles on s.UserId equals u.UserId // where s.UserId == userId // select s; // item = res.FirstOrDefault(); StoreUserCache.Set(key, item, MemoryCacheHelper.CacheAbsoluteExpirationPolicy(ProjectAppSettings.GetWebConfigInt("MainMenuNavigation_CacheAbsoluteExpiration_Minute", 10))); } return(item); }
public SitemapResult RetailersSitemapResult(Controller sitemapsController) { var sitemapItems = new List <SitemapItem>(); String key = String.Format("RetailersSiteMap-{0}", StoreId); RetailerSitemapItemCache.TryGet(key, out sitemapItems); if (sitemapItems == null) { sitemapItems = new List <SitemapItem>(); var retailers = RetailerRepository.GetRetailers(MyStore.Id, null, true); foreach (var retailer in retailers) { var retailerDetailLink = LinkHelper.GetRetailerIdRouteValue(retailer); var siteMap = new SitemapItem(sitemapsController.Url.AbsoluteAction("detail", "retailers", new { id = retailerDetailLink }), changeFrequency: SitemapChangeFrequency.Monthly, priority: 1.0); sitemapItems.Add(siteMap); } RetailerSitemapItemCache.Set(key, sitemapItems, MemoryCacheHelper.CacheAbsoluteExpirationPolicy(ProjectAppSettings.CacheLongSeconds)); } return(new SitemapResult(sitemapItems)); }
public StorePagedList <ProductCategory> GetProductCategoryWithContents(int categoryId, int page, int pageSize = 25) { String key = String.Format("GetProductCategoryWithContents-{0}-{1}", categoryId, page); StorePagedList <ProductCategory> items = null; PagingProductCategoryCache.TryGet(key, out items); if (items == null) { IQueryable <ProductCategory> cats = StoreDbContext.ProductCategories.Where(r => r.Id == categoryId && r.Products.Any()) .Include( r => r.Products.Select( r1 => r1.ProductFiles.Select(m => m.FileManager))) .OrderByDescending(r => r.Ordering); var c = cats.ToList(); items = new StorePagedList <ProductCategory>(c.Skip((page - 1) * pageSize).Take(pageSize).ToList(), page, c.Count()); PagingProductCategoryCache.Set(key, items, MemoryCacheHelper.CacheAbsoluteExpirationPolicy(ProjectAppSettings.GetWebConfigInt("ProductCategories_CacheAbsoluteExpiration_Minute", 10))); } return(items); }
public ActionResult ProductCategories() { var sitemapItems = new List <SitemapItem>(); String key = String.Format("ProductCategoriesSiteMap-{0}", StoreId); ProductSitemapItemCache.TryGet(key, out sitemapItems); if (sitemapItems == null) { sitemapItems = new List <SitemapItem>(); var categories = ProductCategoryService.GetProductCategoriesByStoreIdFromCache(StoreId, StoreConstants.ProductType); foreach (var category in categories) { var productDetailLink = LinkHelper.GetProductCategoryIdRouteValue(category); var siteMap = new SitemapItem(Url.AbsoluteAction("category", "productcategories", new { id = productDetailLink }), changeFrequency: SitemapChangeFrequency.Monthly, priority: 1.0); sitemapItems.Add(siteMap); } ProductSitemapItemCache.Set(key, sitemapItems, MemoryCacheHelper.CacheAbsoluteExpirationPolicy(ProjectAppSettings.CacheLongSeconds)); } return(new SitemapResult(sitemapItems)); }