Ejemplo n.º 1
0
        internal static void InvalidateApiKeysCache(string accountNameKey)
        {
            IDatabase cache = Sahara.Core.Settings.Azure.Redis.RedisMultiplexers.RedisMultiplexer.GetDatabase();

            try
            {
                cache.KeyDelete(AccountApiKeysHash.Key(accountNameKey));
            }
            catch
            {
            }
        }
Ejemplo n.º 2
0
        public static List <ApiKeyModel> GetApiKeys(Account account, bool useCachedVersion = true)
        {
            List <ApiKeyModel> keys = null;

            IDatabase cache          = Sahara.Core.Settings.Azure.Redis.RedisMultiplexers.RedisMultiplexer.GetDatabase();
            string    redisHashField = string.Empty;

            redisHashField = AccountApiKeysHash.Fields.List();

            if (useCachedVersion)
            {
                #region Get keys from cache

                try
                {
                    var redisValue = cache.HashGet(AccountApiKeysHash.Key(account.AccountNameKey), redisHashField);
                    if (redisValue.HasValue)
                    {
                        keys = JsonConvert.DeserializeObject <List <ApiKeyModel> >(redisValue);
                    }
                }
                catch
                {
                }

                #endregion
            }
            if (keys == null)
            {
                #region Get keys from SQL

                keys = Sql.Statements.SelectStatements.SelectApiKeysList(account.SqlPartition, account.SchemaName);

                #endregion

                #region Store keys into cache

                try
                {
                    cache.HashSet(AccountApiKeysHash.Key(account.AccountNameKey), redisHashField, JsonConvert.SerializeObject(keys), When.Always, CommandFlags.FireAndForget);
                }
                catch
                {
                }

                #endregion
            }

            return(keys);
        }