Пример #1
0
 /// <summary>
 /// EventHub queue cache.
 /// </summary>
 /// <param name="partition">Partition this instance is caching.</param>
 /// <param name="defaultMaxAddCount">Default max number of items that can be added to the cache between purge calls.</param>
 /// <param name="bufferPool">raw data block pool.</param>
 /// <param name="dataAdapter">Adapts EventData to cached.</param>
 /// <param name="evictionStrategy">Eviction strategy manage purge related events</param>
 /// <param name="checkpointer">Logic used to store queue position.</param>
 /// <param name="logger"></param>
 /// <param name="cacheMonitor"></param>
 /// <param name="cacheMonitorWriteInterval"></param>
 /// <param name="metadataMinTimeInCache"></param>
 public EventHubQueueCache(
     string partition,
     int defaultMaxAddCount,
     IObjectPool <FixedSizeBuffer> bufferPool,
     IEventHubDataAdapter dataAdapter,
     IEvictionStrategy evictionStrategy,
     IStreamQueueCheckpointer <string> checkpointer,
     ILogger logger,
     ICacheMonitor cacheMonitor,
     TimeSpan?cacheMonitorWriteInterval,
     TimeSpan?metadataMinTimeInCache)
 {
     this.Partition          = partition;
     this.defaultMaxAddCount = defaultMaxAddCount;
     this.bufferPool         = bufferPool;
     this.dataAdapter        = dataAdapter;
     this.checkpointer       = checkpointer;
     this.cache                            = new PooledQueueCache(dataAdapter, logger, cacheMonitor, cacheMonitorWriteInterval, metadataMinTimeInCache);
     this.cacheMonitor                     = cacheMonitor;
     this.evictionStrategy                 = evictionStrategy;
     this.evictionStrategy.OnPurged        = this.OnPurge;
     this.evictionStrategy.PurgeObservable = this.cache;
     this.cachePressureMonitor             = new AggregatedCachePressureMonitor(logger, cacheMonitor);
     this.logger                           = logger;
 }
Пример #2
0
 /// <summary>
 /// Pooled cache for memory stream provider
 /// </summary>
 /// <param name="bufferPool"></param>
 /// <param name="purgePredicate"></param>
 /// <param name="logger"></param>
 /// <param name="serializer"></param>
 /// <param name="cacheMonitor"></param>
 /// <param name="monitorWriteInterval">monitor write interval.  Only triggered for active caches.</param>
 public MemoryPooledCache(IObjectPool <FixedSizeBuffer> bufferPool, TimePurgePredicate purgePredicate, ILogger logger, TSerializer serializer, ICacheMonitor cacheMonitor, TimeSpan?monitorWriteInterval)
 {
     this.bufferPool       = bufferPool;
     this.serializer       = serializer;
     this.cache            = new PooledQueueCache(this, logger, cacheMonitor, monitorWriteInterval);
     this.evictionStrategy = new ChronologicalEvictionStrategy(logger, purgePredicate, cacheMonitor, monitorWriteInterval)
     {
         PurgeObservable = cache
     };
 }
Пример #3
0
        /// <summary>
        /// Pooled cache for generator stream provider
        /// </summary>
        /// <param name="bufferPool"></param>
        /// <param name="logger"></param>
        /// <param name="serializationManager"></param>
        /// <param name="cacheMonitor"></param>
        /// <param name="monitorWriteInterval">monitor write interval.  Only triggered for active caches.</param>
        public GeneratorPooledCache(IObjectPool <FixedSizeBuffer> bufferPool, ILogger logger, SerializationManager serializationManager, ICacheMonitor cacheMonitor, TimeSpan?monitorWriteInterval)
        {
            this.bufferPool           = bufferPool;
            this.serializationManager = serializationManager;
            cache = new PooledQueueCache(this, logger, cacheMonitor, monitorWriteInterval);
            TimePurgePredicate purgePredicate = new TimePurgePredicate(TimeSpan.FromMinutes(5), TimeSpan.FromMinutes(10));

            this.evictionStrategy = new ChronologicalEvictionStrategy(logger, purgePredicate, cacheMonitor, monitorWriteInterval)
            {
                PurgeObservable = cache
            };
        }
Пример #4
0
 /// <summary>
 /// Construct EventHub queue cache.
 /// </summary>
 /// <param name="defaultMaxAddCount">Default max number of items that can be added to the cache between purge calls.</param>
 /// <param name="checkpointer">Logic used to store queue position.</param>
 /// <param name="cacheDataAdapter">Performs data transforms appropriate for the various types of queue data.</param>
 /// <param name="comparer">Compares cached data</param>
 /// <param name="logger"></param>
 /// <param name="evictionStrategy">Eviction stretagy manage purge related events</param>
 protected EventHubQueueCache(int defaultMaxAddCount, IStreamQueueCheckpointer <string> checkpointer, ICacheDataAdapter <EventData, TCachedMessage> cacheDataAdapter,
                              ICacheDataComparer <TCachedMessage> comparer, Logger logger, IEvictionStrategy <TCachedMessage> evictionStrategy)
 {
     this.defaultMaxAddCount = defaultMaxAddCount;
     Checkpointer            = checkpointer;
     cache = new PooledQueueCache <EventData, TCachedMessage>(cacheDataAdapter, comparer, logger);
     this.evictionStrategy                 = evictionStrategy;
     this.evictionStrategy.OnPurged        = this.OnPurge;
     this.evictionStrategy.PurgeObservable = cache;
     cacheDataAdapter.OnBlockAllocated     = this.evictionStrategy.OnBlockAllocated;
     this.cachePressureMonitor             = new AggregatedCachePressureMonitor(logger);
 }
Пример #5
0
 /// <summary>
 /// Construct EventHub queue cache.
 /// </summary>
 /// <param name="defaultMaxAddCount">Default max number of items that can be added to the cache between purge calls.</param>
 /// <param name="checkpointer">Logic used to store queue position.</param>
 /// <param name="cacheDataAdapter">Performs data transforms appropriate for the various types of queue data.</param>
 /// <param name="comparer">Compares cached data</param>
 /// <param name="logger"></param>
 /// <param name="evictionStrategy">Eviction stretagy manage purge related events</param>
 /// <param name="cacheMonitor"></param>
 /// <param name="cacheMonitorWriteInterval"></param>
 protected EventHubQueueCache(int defaultMaxAddCount, IStreamQueueCheckpointer <string> checkpointer, ICacheDataAdapter <EventData, TCachedMessage> cacheDataAdapter,
                              ICacheDataComparer <TCachedMessage> comparer, Logger logger, IEvictionStrategy <TCachedMessage> evictionStrategy,
                              ICacheMonitor cacheMonitor, TimeSpan?cacheMonitorWriteInterval)
 {
     this.defaultMaxAddCount = defaultMaxAddCount;
     Checkpointer            = checkpointer;
     cache                          = new PooledQueueCache <EventData, TCachedMessage>(cacheDataAdapter, comparer, logger, cacheMonitor, cacheMonitorWriteInterval);
     this.cacheMonitor              = cacheMonitor;
     this.evictionStrategy          = evictionStrategy;
     this.evictionStrategy.OnPurged = this.OnPurge;
     this.cachePressureMonitor      = new AggregatedCachePressureMonitor(logger, cacheMonitor);
     EvictionStrategyCommonUtils.WireUpEvictionStrategy <EventData, TCachedMessage>(this.cache, cacheDataAdapter, this.evictionStrategy);
 }
Пример #6
0
        public MemCache(ulong capacity, IScheduler scheduler)
        {
            _scheduler            = scheduler;
            Capacity              = capacity;
            _notificationsSubject = new Subject <ICacheNotification>();

            var lruStrategy = new LruEvictionStrategy(this);

            _evictionStrategy = lruStrategy;

            // TODO: replace this with some other kind of scheduling. Perhaps a sorted list...
            _interval = Observable.Interval(TimeSpan.FromSeconds(1), _scheduler).
                        Subscribe(_ => RemoveExpired());
        }
Пример #7
0
 public QueueCacheForTesting(int defaultMaxAddCount, IObjectPool <FixedSizeBuffer> bufferPool, IEventHubDataAdapter dataAdapter, IEvictionStrategy evictionStrategy, IStreamQueueCheckpointer <string> checkpointer, ILogger logger,
                             ICacheMonitor cacheMonitor, TimeSpan?cacheMonitorWriteInterval)
     : base("test", defaultMaxAddCount, bufferPool, dataAdapter, evictionStrategy, checkpointer, logger, cacheMonitor, cacheMonitorWriteInterval)
 {
 }
Пример #8
0
 public EventHubQueueCacheForTesting(IObjectPool <FixedSizeBuffer> bufferPool, IEventHubDataAdapter dataAdapter, IEvictionStrategy evictionStrategy, IStreamQueueCheckpointer <string> checkpointer,
                                     ILogger logger)
     : base("test", EventHubAdapterReceiver.MaxMessagesPerRead, bufferPool, dataAdapter, evictionStrategy, checkpointer, logger, null, null)
 {
 }
Пример #9
0
 public EventHubQueueCacheForTesting(IStreamQueueCheckpointer <string> checkpointer, ICacheDataAdapter <EventData, CachedEventHubMessage> cacheDataAdapter,
                                     ICacheDataComparer <CachedEventHubMessage> comparer, Logger logger, IEvictionStrategy <CachedEventHubMessage> evictionStrategy)
     : base(checkpointer, cacheDataAdapter, comparer, logger, evictionStrategy)
 {
 }
Пример #10
0
 public CachedMessageConverter(IObjectPool <FixedSizeBuffer> bufferPool, IEvictionStrategy evictionStrategy)
 {
     this.bufferPool       = bufferPool;
     this.evictionStrategy = evictionStrategy;
 }
 public QueueCacheForTesting(int defaultMaxAddCount, IStreamQueueCheckpointer <string> checkpointer, ICacheDataAdapter <EventData, CachedEventHubMessage> cacheDataAdapter,
                             ICacheDataComparer <CachedEventHubMessage> comparer, ILogger logger, IEvictionStrategy <CachedEventHubMessage> evictionStrategy,
                             ICacheMonitor cacheMonitor, TimeSpan?cacheMonitorWriteInterval)
     : base(defaultMaxAddCount, checkpointer, cacheDataAdapter, comparer, logger, evictionStrategy, cacheMonitor, cacheMonitorWriteInterval)
 {
 }
Пример #12
0
 public static void WireUpEvictionStrategy <TQueueMessage, TCachedMessage>(PooledQueueCache <TQueueMessage, TCachedMessage> cache,
                                                                           ICacheDataAdapter <TQueueMessage, TCachedMessage> cacheDataAdapter, IEvictionStrategy <TCachedMessage> evictionStrategy)
     where TCachedMessage : struct
 {
     evictionStrategy.PurgeObservable  = cache;
     cacheDataAdapter.OnBlockAllocated = evictionStrategy.OnBlockAllocated;
 }
Пример #13
0
 public CacheStore(IEvictionStrategy <TKey, TValue> evictionStrategy)
 {
     this.c_evictionStrategy = evictionStrategy;
 }