Esempio n. 1
0
        /// <summary>
        /// </summary>
        /// <param name="items"></param>
        /// <param name="excludeFromEviction">used only for non persistent case</param>
        internal void InternalPutMany(IList <PackedObject> items, bool excludeFromEviction)
        {
            var isBulkOperation = items.Count > Constants.BulkThreshold;

            var toUpdate = new List <PackedObject>();

            try
            {
                Dbg.Trace($"begin InternalPutMany with {items.Count} object");


                InternalBeginBulkInsert(isBulkOperation);

                foreach (var item in items)
                {
                    if (DataByPrimaryKey.ContainsKey(item.PrimaryKey))
                    {
                        toUpdate.Add(item);
                    }
                    else
                    {
                        InternalAddNew(item, excludeFromEviction);
                    }
                }
            }
            finally
            {
                InternalEndBulkInsert(isBulkOperation);

                // update items outside the bulk insert

                if (toUpdate.Count > Constants.BulkThreshold) // bulk optimization for updates
                {
                    RemoveMany(toUpdate);

                    InternalPutMany(toUpdate, true);
                }
                else
                {
                    foreach (var cachedObject in toUpdate)
                    {
                        InternalUpdate(cachedObject);
                    }
                }

                foreach (var cachedObject in toUpdate)
                {
                    EvictionPolicy.Touch(cachedObject);
                }


                Dbg.Trace($"end InternalPutMany with {items.Count} object");
            }
        }
Esempio n. 2
0
        /// <summary>
        ///     Update an object previously stored
        ///     The primary key must be the same, all others can change
        /// </summary>
        /// <param name="item"></param>
        public void InternalUpdate(PackedObject item)
        {
            if (item == null)
            {
                throw new ArgumentNullException(nameof(item));
            }

            if (!DataByPrimaryKey.ContainsKey(item.PrimaryKey))
            {
                var msg = $"Update called for the object {item} which is not stored in the cache";
                throw new NotSupportedException(msg);
            }

            InternalRemoveByPrimaryKey(item.PrimaryKey);
            InternalAddNew(item);

            EvictionPolicy.Touch(item);
        }
Esempio n. 3
0
        /// <summary>
        ///     Like a bulk insert on an empty datastore. Used internally to reindex data when type description changed
        /// </summary>
        /// <param name="items"></param>
        private void InternalReindex(IEnumerable <PackedObject> items)
        {
            var toUpdate = new List <PackedObject>();

            try
            {
                InternalBeginBulkInsert(true);

                foreach (var item in items)
                {
                    InternalAddNew(item, true);
                }
            }
            finally
            {
                InternalEndBulkInsert(true);

                // update items outside the bulk insert

                if (toUpdate.Count > Constants.BulkThreshold) // bulk optimization for updates
                {
                    RemoveMany(toUpdate);

                    InternalPutMany(toUpdate, true);
                }
                else
                {
                    foreach (var cachedObject in toUpdate)
                    {
                        InternalUpdate(cachedObject);
                    }
                }

                //TODO check if necessary
                foreach (var cachedObject in toUpdate)
                {
                    EvictionPolicy.Touch(cachedObject);
                }
            }
        }
Esempio n. 4
0
 public void Touch(PackedObject packedObject)
 {
     EvictionPolicy?.Touch(packedObject);
 }