internal static void InvalidateApiKeysCache(string accountNameKey) { IDatabase cache = Sahara.Core.Settings.Azure.Redis.RedisMultiplexers.RedisMultiplexer.GetDatabase(); try { cache.KeyDelete(AccountApiKeysHash.Key(accountNameKey)); } catch { } }
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); }