public void OnEntryRemoved(string key) { var command = new CacheCommand { Type = CacheCommandType.Remove, Entries = new[] { new CacheEntry { Key = key } } }; // When an entry is removed let all subscribers know var context = _server.ConnectionManager.GetConnectionContext<CacheConnection>(); context.Connection.Broadcast(command); }
public Task Delete(string key) { var command = new CacheCommand { Type = CacheCommandType.Remove, Entries = new[] { new CacheEntry { Key = key } } }; // Execute local delete object value; _cache.TryRemove(key, out value); return SendCommand(command); }
public Task Add(string key, object value) { var entry = new[] { new CacheEntry { Key = key, Value = value } }; var command = new CacheCommand { Type = CacheCommandType.Add, Entries = entry }; // Make it available immediately to the local cache _cache.AddOrUpdate(key, value, (k, v) => value); return SendCommand(command); }
private Task SendCommand(CacheCommand command) { return _connection.Send(JsonConvert.SerializeObject(command)); }
protected override Task OnConnectedAsync(IRequest request, string connectionId) { var command = new CacheCommand { Type = CacheCommandType.Add, Entries = _cache.Store.GetAll().ToArray() }; // REVIEW: Should we send all of the data to the client on reconnect? // Let the client request a subset of the data or none at all. return Connection.Send(connectionId, command); }