public static void UpdateAccountCreditCardInfoCache(string accountId, AccountCreditCardInfo accountCreditCardInfo) { //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.HashSet( AccountByIdHash.Key(accountId), AccountByIdHash.Fields.CreditCard, JsonConvert.SerializeObject(accountCreditCardInfo), When.Always, CommandFlags.FireAndForget ); // Set or extend expiration cache.KeyExpire(AccountByStripeIdHash.Key(accountId), AccountByStripeIdHash.Expiration); } catch { } }
public static void InvalidateAccountCacheById(string id) { //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( AccountByIdHash.Key(id), CommandFlags.FireAndForget ); } catch { } }
public static AccountCreditCardInfo GetAccountCreditCardInfoCache(string accountId) { //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(); AccountCreditCardInfo cachedCreditCardInfo = null; try { var redisValue = cache.HashGet(AccountByIdHash.Key(accountId), AccountByIdHash.Fields.CreditCard); if (redisValue.HasValue) { cachedCreditCardInfo = JsonConvert.DeserializeObject <AccountCreditCardInfo>(redisValue); } } catch { } return(cachedCreditCardInfo); }
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 { } }