Exemplo n.º 1
0
        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
            {
            }
        }
Exemplo n.º 2
0
        public static void InvalidateAccountCacheByStripeId(string stripeId)
        {
            //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(
                    AccountByStripeIdHash.Key(stripeId),
                    CommandFlags.FireAndForget
                    );
            }
            catch
            {
            }
        }
Exemplo n.º 3
0
        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
            {
            }
        }