示例#1
0
        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);
        }
示例#2
0
        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);
        }
示例#3
0
        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);
        }
示例#4
0
 private Task SendCommand(CacheCommand command)
 {
     return _connection.Send(JsonConvert.SerializeObject(command));
 }
示例#5
0
            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);
            }