public static int GetPropertyCount(Account account, bool useCachedVersion = true) { int count = 0; string cachedCount = null; //IDatabase cache = Sahara.Core.Settings.Azure.Redis.RedisMultiplexers.AccountManager_Multiplexer.GetDatabase(); IDatabase cache = Sahara.Core.Settings.Azure.Redis.RedisMultiplexers.RedisMultiplexer.GetDatabase(); string redisHashField = ApplicationPropertiesHash.Fields.Count(); if (useCachedVersion) { #region Get count from cache try { var redisValue = cache.HashGet(ApplicationPropertiesHash.Key(account.AccountNameKey), redisHashField); if (redisValue.HasValue) { cachedCount = JsonConvert.DeserializeObject <string>(redisValue); } } catch { } #endregion } if (cachedCount == null) { #region Get count from SQL count = Sql.Statements.SelectStatements.SelectPropertyCount(account.SqlPartition, account.SchemaName); #endregion #region Store count into cache (by Name only) try { cache.HashSet(ApplicationPropertiesHash.Key(account.AccountNameKey), redisHashField, JsonConvert.SerializeObject(count), When.Always, CommandFlags.FireAndForget); } catch { } #endregion } else { count = Convert.ToInt32(cachedCount); } return(count); }
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 { } }
public static List <PropertyModel> GetProperties(Account account, PropertyListType listType, bool useCachedVersion = true) { List <PropertyModel> properties = null; //IDatabase cache = Sahara.Core.Settings.Azure.Redis.RedisMultiplexers.AccountManager_Multiplexer.GetDatabase(); IDatabase cache = Sahara.Core.Settings.Azure.Redis.RedisMultiplexers.RedisMultiplexer.GetDatabase(); string redisHashField = ApplicationPropertiesHash.Fields.All(); switch (listType) { case PropertyListType.All: redisHashField = ApplicationPropertiesHash.Fields.All(); break; case PropertyListType.Listings: redisHashField = ApplicationPropertiesHash.Fields.Listings(); break; case PropertyListType.Details: redisHashField = ApplicationPropertiesHash.Fields.Details(); break; case PropertyListType.Featured: redisHashField = ApplicationPropertiesHash.Fields.Featured(); break; } if (useCachedVersion) { #region Get properties from cache try { var redisValue = cache.HashGet(ApplicationPropertiesHash.Key(account.AccountNameKey), redisHashField); if (redisValue.HasValue) { properties = JsonConvert.DeserializeObject <List <PropertyModel> >(redisValue); } } catch { } #endregion } if (properties == null) { #region Get properties from SQL properties = Sql.Statements.SelectStatements.SelectPropertyList(account.SqlPartition, account.SchemaName); #region Append account cdn link to all swatch images var cdnEndpoint = Core.Settings.Azure.Storage.GetStoragePartition(account.StoragePartition).CDN; foreach (var property in properties) { if (property.PropertyTypeNameKey == "swatch") { foreach (var swatch in property.Swatches) { swatch.PropertySwatchImage = "https://" + cdnEndpoint + "/" + swatch.PropertySwatchImage; swatch.PropertySwatchImageMedium = "https://" + cdnEndpoint + "/" + swatch.PropertySwatchImageMedium; swatch.PropertySwatchImageSmall = "https://" + cdnEndpoint + "/" + swatch.PropertySwatchImageSmall; } } } #endregion #endregion #region Store properties into cache (by all, listing & details) #region build seperate property lists var listingProperties = new List <PropertyModel>(); var detailProperties = new List <PropertyModel>(); var feturedProperties = new List <PropertyModel>(); foreach (var property in properties) { if (property.Listing) { listingProperties.Add(property); } if (property.Details) { detailProperties.Add(property); } if (property.FeaturedID > 0) { feturedProperties.Add(property); } } listingProperties = listingProperties.OrderBy(o => o.OrderID).ToList(); detailProperties = detailProperties.OrderBy(o => o.OrderID).ToList(); feturedProperties = feturedProperties.OrderBy(o => o.FeaturedID).ToList(); #endregion try { //All cache.HashSet(ApplicationPropertiesHash.Key(account.AccountNameKey), ApplicationPropertiesHash.Fields.All(), JsonConvert.SerializeObject(properties), When.Always, CommandFlags.FireAndForget); //Listing cache.HashSet(ApplicationPropertiesHash.Key(account.AccountNameKey), ApplicationPropertiesHash.Fields.Listings(), JsonConvert.SerializeObject(listingProperties), When.Always, CommandFlags.FireAndForget); //Details cache.HashSet(ApplicationPropertiesHash.Key(account.AccountNameKey), ApplicationPropertiesHash.Fields.Details(), JsonConvert.SerializeObject(detailProperties), When.Always, CommandFlags.FireAndForget); //Featured cache.HashSet(ApplicationPropertiesHash.Key(account.AccountNameKey), ApplicationPropertiesHash.Fields.Featured(), JsonConvert.SerializeObject(feturedProperties), When.Always, CommandFlags.FireAndForget); } catch { } #endregion //Assign the correct propertyListType to the return object: switch (listType) { case PropertyListType.Listings: properties = listingProperties; break; case PropertyListType.Details: properties = detailProperties; break; case PropertyListType.Featured: properties = feturedProperties; break; } } return(properties); }
public static PropertyModel GetProperty(Account account, string propertyNameKey, bool useCachedVersion = true) { PropertyModel property = null; #region Create Cache & HashField string redisHashField = string.Empty; //IDatabase cache = Sahara.Core.Settings.Azure.Redis.RedisMultiplexers.AccountManager_Multiplexer.GetDatabase(); IDatabase cache = Sahara.Core.Settings.Azure.Redis.RedisMultiplexers.RedisMultiplexer.GetDatabase(); redisHashField = ApplicationPropertiesHash.Fields.Details(Common.Methods.ObjectNames.ConvertToObjectNameKey(propertyNameKey)); #endregion if (useCachedVersion) { #region Get property from cache (if user requests by name) try { var redisValue = cache.HashGet(ApplicationPropertiesHash.Key(account.AccountNameKey), redisHashField); if (redisValue.HasValue) { property = JsonConvert.DeserializeObject <PropertyModel>(redisValue); } } catch { } #endregion } if (property == null) { #region Get property from SQL property = Sql.Statements.SelectStatements.SelectProperty(account.SqlPartition, account.SchemaName, propertyNameKey); #endregion if (property != null) { #region Store property into cache (using short names ONLY) try { cache.HashSet(ApplicationPropertiesHash.Key(account.AccountNameKey), ApplicationPropertiesHash.Fields.Details(property.PropertyNameKey), JsonConvert.SerializeObject(property), When.Always, CommandFlags.FireAndForget); } catch { } #endregion } } return(property); }