public async Task AddMessage(ChatMessageData message) { try { var messageCache = await GetMessages(); if (messageCache.Count > _historyCount) { await _chatMessages.RemoveAsync(messageCache.Min(x => x.Id).ToString()); } using (var context = new ApplicationDbContext()) { var chatMessage = new ChatMessage { Message = message.Message, Timestamp = message.Timestamp, UserId = message.UserId, IsEnabled = true }; context.ChatMessages.Add(chatMessage); await context.SaveChangesAsync(); message.Id = chatMessage.Id; await _chatMessages.AddAsync(message.Id.ToString(), message); } } catch (Exception) { } }
public static async Task <bool> UpdateApiAuthKey(UpdateApiModel apiData) { await _rediscache.RemoveAsync(apiData.OldApiKey); var result = await GetApiAuthKey(apiData.ApiKey); return(result != null); }
public async Task RemoveAsync_WithDefaultOptions_RemovesFromCache() { // Arrange var cache = CreateDistributedCache(); await cache.SetAsync("testhost:SimpleConcepts.DistributedDictionary.Tests.TestPerson:054392d5-1a51-4f8a-96c7-2a3eb0db2842", new byte[] { 123, 34, 78, 97, 109, 101, 34, 58, 34, 82, 97, 112, 104, 97, 101, 108, 34, 44, 34, 65, 103, 101, 34, 58, 51, 49, 125 }); var dic = new DistributedDictionary <Guid, TestPerson>(cache, new OptionsWrapper <DistributedDictionaryOptions>(new DistributedDictionaryOptions())); var key = Guid.Parse("054392d5-1a51-4f8a-96c7-2a3eb0db2842"); // Act await dic.RemoveAsync(key); // Assert var bytes = await cache.GetAsync("testhost:SimpleConcepts.DistributedDictionary.Tests.TestPerson:054392d5-1a51-4f8a-96c7-2a3eb0db2842"); Assert.Null(bytes); }
public async Task RemoveOnlineUser(string userId) { await _onlineUsers.RemoveAsync(userId); }