예제 #1
0
        /// <summary>
        /// Calculates the hybrid checksum, this is used to
        /// create rate for every specific object in the cache
        /// based on various object attributes.
        /// <remarks>
        /// The calculate done like this: HybridChecksum((c.HitRatio + ((c.ObjectSize / 1024) + (c.Span.Ticks / 1024) + (c.UsageDatetime.Ticks / 1024))));
        /// </remarks>
        /// </summary>
        /// <param name="c">an object of type <see cref="Cleanup"/></param>
        /// <param name="currentConfiguration">The current configuration.</param>
        /// <returns>a rate as <see cref="long"/></returns>
        public static long CalculateHybridChecksum(Cleanup c, Enums.ServiceCacheCleanUp currentConfiguration)
        {
            #region Access Log
#if TRACE
            {
                Handler.LogHandler.Tracking("Access Method: " + typeof(CacheCleanup).FullName + "->" + ((object)MethodBase.GetCurrentMethod()).ToString() + " ;");
            }
#endif
            #endregion Access Log

            // do not make Hybrid calculations on other cleanup strategy - boost performance
            if (currentConfiguration == Enums.ServiceCacheCleanUp.HYBRID)
            {
                return(HybridChecksum((c.HitRatio + ((c.ObjectSize / 1024) + (c.Span.Ticks / 1024) + (c.UsageDatetime.Ticks / 1024)))));
            }
            return(0);
        }
예제 #2
0
        /// <summary>
        /// Updates the specified msg or its updating the available record if its already added.
        /// </summary>
        /// <param name="msg">The MSG.</param>
        public void Update(IndexusMessage msg)
        {
            #region Access Log
#if TRACE
            {
                Handler.LogHandler.Tracking("Access Method: " + this.GetType().ToString() + "->" + ((object)MethodBase.GetCurrentMethod()).ToString() + " ;");
            }
#endif
            #endregion Access Log

            lock (BulkObject)
            {
                Cleanup c;
                if (this.CleanupDict.ContainsKey(msg.Key))
                {
                    c = this.CleanupDict[msg.Key];
                    // update
                    if (msg.Payload != null)
                    {
                        c.ObjectSize = msg.Payload.Length == 1 ? c.ObjectSize : msg.Payload.Length;
                    }
                    else
                    {
                        c.ObjectSize = 0;
                    }

                    c.Prio          = msg.ItemPriority;
                    c.HitRatio     += 1;
                    c.HybridPoint   = CalculateHybridChecksum(c, this.CleanupCacheConfiguration);
                    c.Span          = msg.Expires.Subtract(DateTime.Now);
                    c.UsageDatetime = DateTime.Now;
                }
                else
                {
                    // add
                    // object is not available, create a new instance / calculations / and add it to the list.
                    var cleanup = new Cleanup(msg.Key, msg.ItemPriority, msg.Expires.Subtract(DateTime.Now), 0, DateTime.Now, msg.Payload != null ? msg.Payload.Length : 0, 0);
                    cleanup.HybridPoint       = CalculateHybridChecksum(cleanup, this.CleanupCacheConfiguration);
                    this.CleanupDict[msg.Key] = cleanup;
                }
            }
        }