Exemplo n.º 1
0
        /// <summary>
        /// Pooled queue cache is a cache of message that obtains resource from a pool
        /// </summary>
        /// <param name="cacheDataAdapter"></param>
        /// <param name="comparer"></param>
        /// <param name="logger"></param>
        /// <param name="cacheMonitor"></param>
        /// <param name="cacheMonitorWriteInterval">cache monitor write interval.  Only triggered for active caches.</param>
        public PooledQueueCache(ICacheDataAdapter <TQueueMessage, TCachedMessage> cacheDataAdapter, ICacheDataComparer <TCachedMessage> comparer, ILogger logger, ICacheMonitor cacheMonitor, TimeSpan?cacheMonitorWriteInterval)
        {
            if (cacheDataAdapter == null)
            {
                throw new ArgumentNullException("cacheDataAdapter");
            }
            if (comparer == null)
            {
                throw new ArgumentNullException("comparer");
            }
            if (logger == null)
            {
                throw new ArgumentNullException("logger");
            }
            this.cacheDataAdapter = cacheDataAdapter;
            this.comparer         = comparer;
            this.logger           = logger;
            this.itemCount        = 0;
            pool              = new CachedMessagePool <TQueueMessage, TCachedMessage>(cacheDataAdapter);
            messageBlocks     = new LinkedList <CachedMessageBlock <TCachedMessage> >();
            this.cacheMonitor = cacheMonitor;

            if (this.cacheMonitor != null && cacheMonitorWriteInterval.HasValue)
            {
                this.periodicMonitoring = new PeriodicAction(cacheMonitorWriteInterval.Value, this.ReportCacheMessageStatistics);
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// Simple object pool
        /// </summary>
        /// <param name="factoryFunc">Function used to create new resources of type T</param>
        /// <param name="monitor">monitor to report statistics for object pool</param>
        /// <param name="monitorWriteInterval"></param>
        public ObjectPool(Func <T> factoryFunc, IObjectPoolMonitor monitor = null, TimeSpan?monitorWriteInterval = null)
        {
            if (factoryFunc == null)
            {
                throw new ArgumentNullException("factoryFunc");
            }

            this.factoryFunc = factoryFunc;
            pool             = new ConcurrentStack <T>();

            // monitoring
            this.monitor = monitor;
            if (this.monitor != null && monitorWriteInterval.HasValue)
            {
                this.periodicMonitoring = new PeriodicAction(monitorWriteInterval.Value, this.ReportObjectPoolStatistics);
            }

            this.totalObjects = 0;
        }
Exemplo n.º 3
0
        /// <summary>
        /// Initializes a new instance of the <see cref="ChronologicalEvictionStrategy"/> class.
        /// </summary>
        /// <param name="logger">The logger.</param>
        /// <param name="timePurage">The time-based purge predicate.</param>
        /// <param name="cacheMonitor">The cache monitor.</param>
        /// <param name="monitorWriteInterval">"Interval to write periodic statistics. Only triggered for active caches.</param>
        public ChronologicalEvictionStrategy(ILogger logger, TimePurgePredicate timePurage, ICacheMonitor cacheMonitor, TimeSpan?monitorWriteInterval)
        {
            if (logger == null)
            {
                throw new ArgumentException(nameof(logger));
            }
            if (timePurage == null)
            {
                throw new ArgumentException(nameof(timePurage));
            }
            this.logger       = logger;
            this.timePurge    = timePurage;
            this.inUseBuffers = new Queue <FixedSizeBuffer>();

            // monitoring
            this.cacheMonitor = cacheMonitor;
            if (this.cacheMonitor != null && monitorWriteInterval.HasValue)
            {
                this.periodicMonitoring = new PeriodicAction(monitorWriteInterval.Value, this.ReportCacheSize);
            }

            this.cacheSizeInByte = 0;
        }