protected void OnReciveCommand(CacheBusCommand command) { if (command.Sequence < _LastReceivedSequence) { return; } if (_LastReceivedSequence > 0) { if (_LastReceivedSequence + 1 < command.Sequence) { PullMissingMessages(_LastReceivedSequence); } } _LastReceivedSequence = command.Sequence.GetValueOrDefault(); if (command.Target != _Target) { return; } if (command.Sender == _InstanceId) { return; } if (command.Name == nameof(RemoveAsync)) { IMemoryCacheDelegate.RemoveAsync(command.Key); } else if (command.Name == nameof(RemoveManyAsync)) { IMemoryCacheDelegate.RemoveAsync(command.Key.ToObjectByJson <List <string> >()); } else if (command.Name == nameof(ClearAsync)) { IMemoryCacheDelegate.ClearAsync(); } else if (command.Name == nameof(AddToSetAsync)) { IMemoryCacheDelegate.AddToSetAsync(command.Key, command.Parameter); } else if (command.Name == nameof(RemoveFromSetAsync)) { IMemoryCacheDelegate.RemoveFromSetAsync(command.Key, command.Parameter); } }
private async Task HandlePurge(CacheBusCommand command) { if (_NextPurge == null) { _NextPurge = ITimeService.Now.AddMinutes(20); _NextPurgeSequence = command.Sequence.Value; } if (ITimeService.Now > _NextPurge) { await Purge(_NextPurgeSequence); _NextPurge = ITimeService.Now.AddMinutes(20); _NextPurgeSequence = command.Sequence.Value; } }
private async Task SendCommand(string name, string key = null, IEnumerable <string> parameter = null) { if (!_Started) { throw new Exception("Start first."); } var command = new CacheBusCommand { Created = ITimeService.Now, Target = _Target, Sender = _InstanceId, Name = name, Key = key, Parameter = parameter }; await TransferCommand(command); await HandlePurge(command); }
protected abstract Task TransferCommand(CacheBusCommand command);