public static void InvalidateAccountCacheByNameKey(string nameKey) { //ConnectionMultiplexer con = ConnectionMultiplexer.Connect(Sahara.Core.Settings.Azure.Redis.RedisConnections.AccountManager_RedisConfiguration); //IDatabase cache = con.GetDatabase(); //IDatabase cache = Sahara.Core.Settings.Azure.Redis.RedisMultiplexers.AccountManager_Multiplexer.GetDatabase(); IDatabase cache = Sahara.Core.Settings.Azure.Redis.RedisMultiplexers.RedisMultiplexer.GetDatabase(); try { cache.KeyDelete( AccountByNameHash.Key(nameKey), CommandFlags.FireAndForget ); } catch { } }
internal static void UpdateAccountInCache(Account account, bool includeNameIdReferences = false, string nameReferenceToClear = null) { //IDatabase cache = Sahara.Core.Settings.Azure.Redis.RedisMultiplexers.AccountManager_Multiplexer.GetDatabase(); IDatabase cache = Sahara.Core.Settings.Azure.Redis.RedisMultiplexers.RedisMultiplexer.GetDatabase(); try { cache.HashSet( AccountByIdHash.Key(account.AccountID.ToString()), AccountByIdHash.Fields.Model, JsonConvert.SerializeObject(account), When.Always, CommandFlags.FireAndForget); // Set Expiration cache.KeyExpire(AccountByIdHash.Key(account.AccountID.ToString()), AccountByIdHash.Expiration); cache.HashSet( AccountByNameHash.Key(account.AccountName), AccountByNameHash.Fields.Model, JsonConvert.SerializeObject(account), When.Always, CommandFlags.FireAndForget); // Set Expiration cache.KeyExpire(AccountByNameHash.Key(account.AccountID.ToString()), AccountByNameHash.Expiration); if (!String.IsNullOrEmpty(account.StripeCustomerID)) { cache.HashSet( AccountByStripeIdHash.Key(account.StripeCustomerID), AccountByStripeIdHash.Fields.Model, JsonConvert.SerializeObject(account), When.Always, CommandFlags.FireAndForget); // Set Expiration cache.KeyExpire(AccountByStripeIdHash.Key(account.AccountID.ToString()), AccountByStripeIdHash.Expiration); } if (includeNameIdReferences) { //Used when account name is changed cache.HashSet( AccountByIdHash.Key(account.AccountID.ToString()), AccountByIdHash.Fields.AccountNameKey, account.AccountNameKey, When.Always, CommandFlags.FireAndForget ); cache.HashSet( AccountByIdHash.Key(account.AccountID.ToString()), AccountByIdHash.Fields.AccountName, account.AccountName, When.Always, CommandFlags.FireAndForget ); cache.HashSet( AccountByNameHash.Key(account.AccountName), AccountByNameHash.Fields.AccountId, account.AccountID.ToString(), When.Always, CommandFlags.FireAndForget ); } if (nameReferenceToClear != null) { cache.KeyDelete( AccountByNameHash.Key(nameReferenceToClear), CommandFlags.FireAndForget ); } } catch { } }