public static List <ProductSearchFacet> GetProductFacets(string accountNameKey, bool includeHidden = true, bool useCachedVersion = true) { List <ProductSearchFacet> productFacets = null; //IDatabase cache = Sahara.Core.Settings.Azure.Redis.RedisMultiplexers.AccountManager_Multiplexer.GetDatabase(); IDatabase cache = Sahara.Core.Settings.Azure.Redis.RedisMultiplexers.RedisMultiplexer.GetDatabase(); string redisHashField = string.Empty; if (includeHidden) { redisHashField = ApplicationSearchHash.Fields.ProductFacets(); } else { redisHashField = ApplicationSearchHash.Fields.ProductFacetsVisible(); } if (useCachedVersion) { #region Get facets from cache try { var redisValue = cache.HashGet(ApplicationSearchHash.Key(accountNameKey), redisHashField); if (redisValue.HasValue) { productFacets = JsonConvert.DeserializeObject <List <ProductSearchFacet> >(redisValue); } } catch { } #endregion } if (productFacets == null) { #region Build Facets From Search Index productFacets = Internal.ProductFacetTasks.BuildProductFacets(accountNameKey, includeHidden); #endregion #region Store count into cache try { cache.HashSet(ApplicationSearchHash.Key(accountNameKey), redisHashField, JsonConvert.SerializeObject(productFacets), When.Always, CommandFlags.FireAndForget); } catch { } #endregion } return(productFacets); }
public static List <ProductSearchSortable> GetProductSortables(string accountNameKey, bool useCachedVersion = true) { List <ProductSearchSortable> productSortables = null; //IDatabase cache = Sahara.Core.Settings.Azure.Redis.RedisMultiplexers.AccountManager_Multiplexer.GetDatabase(); IDatabase cache = Sahara.Core.Settings.Azure.Redis.RedisMultiplexers.RedisMultiplexer.GetDatabase(); string redisHashField = string.Empty; redisHashField = ApplicationSearchHash.Fields.ProductSortables(); if (useCachedVersion) { #region Get sortables from cache try { var redisValue = cache.HashGet(ApplicationSearchHash.Key(accountNameKey), redisHashField); if (redisValue.HasValue) { productSortables = JsonConvert.DeserializeObject <List <ProductSearchSortable> >(redisValue); } } catch { } #endregion } if (productSortables == null) { #region Build Sortables productSortables = Internal.ProductSortingTasks.BuildProductSortables(accountNameKey); #endregion #region Store sortables into cache try { cache.HashSet(ApplicationSearchHash.Key(accountNameKey), redisHashField, JsonConvert.SerializeObject(productSortables), When.Always, CommandFlags.FireAndForget); } catch { } #endregion } return(productSortables); }
internal static void InvalidateProductCaches(string accountNameKey) { //Used to handle public API calls for products only. Admins always use direct DOcumentDB Calls. Only clear this when add products or updating products. //IDatabase cache = Sahara.Core.Settings.Azure.Redis.RedisMultiplexers.AccountManager_Multiplexer.GetDatabase(); IDatabase cache = Sahara.Core.Settings.Azure.Redis.RedisMultiplexers.RedisMultiplexer.GetDatabase(); try { cache.KeyDelete(ApplicationProductHash.Key(accountNameKey)); //We also clear the associated search hash so that facets tied to products are properly updated cache.KeyDelete( ApplicationSearchHash.Key(accountNameKey), CommandFlags.FireAndForget ); } catch { } }
internal static void InvalidateAllPropertyCachesForAccount(string accountNameKey) { //IDatabase cache = Sahara.Core.Settings.Azure.Redis.RedisMultiplexers.AccountManager_Multiplexer.GetDatabase(); IDatabase cache = Sahara.Core.Settings.Azure.Redis.RedisMultiplexers.RedisMultiplexer.GetDatabase(); try { cache.KeyDelete( ApplicationPropertiesHash.Key(accountNameKey), CommandFlags.FireAndForget ); //We also clear the associated search hash so that facets tied to properties are properly updated cache.KeyDelete( ApplicationSearchHash.Key(accountNameKey), CommandFlags.FireAndForget ); } catch { } }