Example #1
0
        protected void BatchMessage(
            IEnumerable <IServerAddress> servers,
            ICacheRefresher refresher,
            MessageType messageType,
            IEnumerable <object> ids = null,
            Type idType = null,
            string json = null)
        {
            var batch        = GetBatch(true);
            var instructions = RefreshInstruction.GetInstructions(refresher, messageType, ids, idType, json);

            // batch if we can, else write to DB immediately
            if (batch == null)
            {
                //only write the json blob with a maximum count of the MaxProcessingInstructionCount
                using (var scope = _appContext.ScopeProvider.CreateScope())
                {
                    foreach (var maxBatch in instructions.InGroupsOf(Options.MaxProcessingInstructionCount))
                    {
                        WriteInstructions(scope, maxBatch);
                    }
                    scope.Complete();
                }
            }
            else
            {
                batch.Add(new RefreshInstructionEnvelope(servers, refresher, instructions));
            }
        }
        protected override void DeliverRemote(
            ICacheRefresher refresher,
            MessageType messageType,
            IEnumerable <object> ids = null,
            string json = null)
        {
            var idsA = ids?.ToArray();

            if (GetArrayType(idsA, out Type idType) == false)
            {
                throw new ArgumentException("All items must be of the same type, either int or Guid.", nameof(ids));
            }

            IEnumerable <RefreshInstruction> instructions = RefreshInstruction.GetInstructions(refresher, JsonSerializer, messageType, idsA, idType, json);

            CacheInstructionService.DeliverInstructions(instructions, LocalIdentity);
        }
        private void BatchMessage(
            ICacheRefresher refresher,
            MessageType messageType,
            IEnumerable <object> ids = null,
            Type idType = null,
            string json = null)
        {
            ICollection <RefreshInstructionEnvelope> batch        = GetBatch(true);
            IEnumerable <RefreshInstruction>         instructions = RefreshInstruction.GetInstructions(refresher, JsonSerializer, messageType, ids, idType, json);

            // Batch if we can, else write to DB immediately.
            if (batch == null)
            {
                CacheInstructionService.DeliverInstructionsInBatches(instructions, LocalIdentity);
            }
            else
            {
                batch.Add(new RefreshInstructionEnvelope(refresher, instructions));
            }
        }
Example #4
0
        protected void BatchMessage(
            IEnumerable <IServerAddress> servers,
            ICacheRefresher refresher,
            MessageType messageType,
            IEnumerable <object> ids = null,
            Type idType = null,
            string json = null)
        {
            var batch        = GetBatch(true);
            var instructions = RefreshInstruction.GetInstructions(refresher, messageType, ids, idType, json);

            // batch if we can, else write to DB immediately
            if (batch == null)
            {
                WriteInstructions(instructions.ToArray());
            }
            else
            {
                batch.Add(new RefreshInstructionEnvelope(servers, refresher, instructions));
            }
        }
Example #5
0
        /// <summary>
        /// Parses out the individual instructions to be processed.
        /// </summary>
        private static List <RefreshInstruction> GetAllInstructions(IEnumerable <JToken> jsonInstructions)
        {
            var result = new List <RefreshInstruction>();

            foreach (JToken jsonItem in jsonInstructions)
            {
                // Could be a JObject in which case we can convert to a RefreshInstruction.
                // Otherwise it could be another JArray - in which case we'll iterate that.
                if (jsonItem is JObject jsonObj)
                {
                    RefreshInstruction instruction = jsonObj.ToObject <RefreshInstruction>();
                    result.Add(instruction);
                }
                else
                {
                    var jsonInnerArray = (JArray)jsonItem;
                    result.AddRange(GetAllInstructions(jsonInnerArray)); // recurse
                }
            }

            return(result);
        }