Пример #1
0
        private CacheManager CreateCacheManager(string cacheManagerName)
        {
            CacheManager cacheManager = cacheManagers[cacheManagerName] as CacheManager;

            if (cacheManager != null)
            {
                return(cacheManager);
            }

            CachingConfigurationView      view             = new CachingConfigurationView(ConfigurationContext);
            CacheManagerData              cacheManagerData = view.GetCacheManagerData(cacheManagerName);
            CacheCapacityScavengingPolicy scavengingPolicy =
                new CacheCapacityScavengingPolicy(cacheManagerName, view);

            IBackingStore backingStore = backingStoreFactory.CreateBackingStore(cacheManagerName);
            Cache         cache        = new Cache(backingStore, scavengingPolicy);

            ExpirationPollTimer timer          = new ExpirationPollTimer();
            ExpirationTask      expirationTask = CreateExpirationTask(cache);
            ScavengerTask       scavengerTask  = new ScavengerTask(cacheManagerName, view, scavengingPolicy, cache);
            BackgroundScheduler scheduler      = new BackgroundScheduler(expirationTask, scavengerTask);

            cache.Initialize(scheduler);

            scheduler.Start();
            timer.StartPolling(new TimerCallback(scheduler.ExpirationTimeoutExpired), cacheManagerData.ExpirationPollFrequencyInSeconds * 1000);

            cacheManager = new CacheManager(cache, scheduler, timer);
            cacheManagers.Add(cacheManagerName, cacheManager);
            return(cacheManager);
        }
        /// <summary>
        /// Made public for testing purposes.
        /// </summary>
        public CacheManager BuildCacheManager(
            string cacheManagerName,
            IBackingStore backingStore,
            int maximumElementsInCacheBeforeScavenging,
            int numberToRemoveWhenScavenging,
            int expirationPollFrequencyInSeconds,
            CachingInstrumentationProvider instrumentationProvider)
        {
            CacheCapacityScavengingPolicy scavengingPolicy =
                new CacheCapacityScavengingPolicy(maximumElementsInCacheBeforeScavenging);

            Cache cache = new Cache(backingStore, scavengingPolicy, instrumentationProvider);

            ExpirationPollTimer timer          = new ExpirationPollTimer();
            ExpirationTask      expirationTask = CreateExpirationTask(cache, instrumentationProvider);
            ScavengerTask       scavengerTask  = new ScavengerTask(numberToRemoveWhenScavenging, scavengingPolicy, cache, instrumentationProvider);
            BackgroundScheduler scheduler      = new BackgroundScheduler(expirationTask, scavengerTask, instrumentationProvider);

            cache.Initialize(scheduler);

            scheduler.Start();
            timer.StartPolling(new TimerCallback(scheduler.ExpirationTimeoutExpired), expirationPollFrequencyInSeconds * 1000);

            return(new CacheManager(cache, scheduler, timer));
        }
Пример #3
0
 internal ScavengerTask(string cacheManagerName, 
                        CachingConfigurationView currentConfigurationData, 
                        CacheCapacityScavengingPolicy scavengingPolicy,
                        ICacheOperations cacheOperations)
 {
     this.scavengingPolicy = scavengingPolicy;
     this.cacheManagerName = cacheManagerName;
     this.currentConfigurationData = currentConfigurationData;
     this.cacheOperations = cacheOperations;
 }
Пример #4
0
 public ScavengerTask(int numberToRemoveWhenScavenging,
                      CacheCapacityScavengingPolicy scavengingPolicy,
                      ICacheOperations cacheOperations,
                      CachingInstrumentationProvider instrumentationProvider)
 {
     this.numberToRemoveWhenScavenging = numberToRemoveWhenScavenging;
     this.scavengingPolicy             = scavengingPolicy;
     this.cacheOperations         = cacheOperations;
     this.instrumentationProvider = instrumentationProvider;
 }
Пример #5
0
        /// <summary>
        /// Initialize a new instance of the <see cref="ScavengerTask"/> with a <see cref="CacheManager"/> name, a <see cref="CachingConfigurationView"/>, the <see cref="CacheCapacityScavengingPolicy"/> and the <see cref="ICacheOperations"/>.
        /// </summary>
        /// <param name="numberToRemoveWhenScavenging">The number of items that should be removed from the cache when scavenging.</param>
        /// <param name="scavengingPolicy">The <see cref="CacheCapacityScavengingPolicy"/> to use.</param>
        /// <param name="cacheOperations">The <see cref="ICacheOperations"/> to perform.</param>
        /// <param name="instrumentationProvider">An instrumentation provider.</param>
        public ScavengerTask(int numberToRemoveWhenScavenging,
							   CacheCapacityScavengingPolicy scavengingPolicy,
							   ICacheOperations cacheOperations,
							   CachingInstrumentationProvider instrumentationProvider)
        {
            this.numberToRemoveWhenScavenging = numberToRemoveWhenScavenging;
            this.scavengingPolicy = scavengingPolicy;
            this.cacheOperations = cacheOperations;
            this.instrumentationProvider = instrumentationProvider;
        }
Пример #6
0
        public Cache(IBackingStore backingStore, CacheCapacityScavengingPolicy scavengingPolicy)
        {
            this.backingStore = backingStore;
            this.scavengingPolicy = scavengingPolicy;

            Hashtable initialItems = backingStore.Load();
            inMemoryCache = Hashtable.Synchronized(initialItems);

            CachingServiceItemTurnoverEvent.SetItemsTotal(Count);
        }
Пример #7
0
 internal ScavengerTask(string cacheManagerName,
                        CachingConfigurationView currentConfigurationData,
                        CacheCapacityScavengingPolicy scavengingPolicy,
                        ICacheOperations cacheOperations)
 {
     this.scavengingPolicy         = scavengingPolicy;
     this.cacheManagerName         = cacheManagerName;
     this.currentConfigurationData = currentConfigurationData;
     this.cacheOperations          = cacheOperations;
 }
Пример #8
0
        public Cache(IBackingStore backingStore, CacheCapacityScavengingPolicy scavengingPolicy)
        {
            this.backingStore     = backingStore;
            this.scavengingPolicy = scavengingPolicy;

            Hashtable initialItems = backingStore.Load();

            inMemoryCache = Hashtable.Synchronized(initialItems);

            CachingServiceItemTurnoverEvent.SetItemsTotal(Count);
        }
Пример #9
0
		/// <summary>
		/// Initialzie a new instance of a <see cref="Cache"/> class with a backing store, and scavenging policy.
		/// </summary>
		/// <param name="backingStore">The cache backing store.</param>
		/// <param name="scavengingPolicy">The scavenging policy.</param>
		/// <param name="instrumentationProvider">The instrumentation provider.</param>
		public Cache(IBackingStore backingStore, CacheCapacityScavengingPolicy scavengingPolicy, CachingInstrumentationProvider instrumentationProvider)
        {
            this.backingStore = backingStore;
            this.scavengingPolicy = scavengingPolicy;
			this.instrumentationProvider = instrumentationProvider;

            Hashtable initialItems = backingStore.Load();
            inMemoryCache = Hashtable.Synchronized(initialItems);

			this.instrumentationProvider.FireCacheUpdated(initialItems.Count, initialItems.Count);
        }
Пример #10
0
        /// <summary>
        /// Initialzie a new instance of a <see cref="Cache"/> class with a backing store, and scavenging policy.
        /// </summary>
        /// <param name="backingStore">The cache backing store.</param>
        /// <param name="scavengingPolicy">The scavenging policy.</param>
        /// <param name="instrumentationProvider">The instrumentation provider.</param>
        public Cache(IBackingStore backingStore, CacheCapacityScavengingPolicy scavengingPolicy, CachingInstrumentationProvider instrumentationProvider)
        {
            this.backingStore            = backingStore;
            this.scavengingPolicy        = scavengingPolicy;
            this.instrumentationProvider = instrumentationProvider;

            Hashtable initialItems = backingStore.Load();

            inMemoryCache = Hashtable.Synchronized(initialItems);

            this.instrumentationProvider.FireCacheUpdated(initialItems.Count, initialItems.Count);
        }
Пример #11
0
        /// <summary>
        /// Made public for testing purposes.
        /// </summary>
        public CacheManager BuildCacheManager(
			string cacheManagerName,
			IBackingStore backingStore,
			int maximumElementsInCacheBeforeScavenging,
			int numberToRemoveWhenScavenging,
			int expirationPollFrequencyInSeconds,
			CachingInstrumentationProvider instrumentationProvider)
        {
            CacheCapacityScavengingPolicy scavengingPolicy =
                new CacheCapacityScavengingPolicy(maximumElementsInCacheBeforeScavenging);

            Cache cache = new Cache(backingStore, scavengingPolicy, instrumentationProvider);

            ExpirationPollTimer timer = new ExpirationPollTimer();
            ExpirationTask expirationTask = CreateExpirationTask(cache, instrumentationProvider);
            ScavengerTask scavengerTask = new ScavengerTask(numberToRemoveWhenScavenging, scavengingPolicy, cache, instrumentationProvider);
            BackgroundScheduler scheduler = new BackgroundScheduler(expirationTask, scavengerTask, instrumentationProvider);
            cache.Initialize(scheduler);

            scheduler.Start();
            timer.StartPolling(new TimerCallback(scheduler.ExpirationTimeoutExpired), expirationPollFrequencyInSeconds * 1000);

            return new CacheManager(cache, scheduler, timer);
        }
Пример #12
0
        private CacheManager CreateCacheManager(string cacheManagerName)
        {
            CacheManager cacheManager = cacheManagers[cacheManagerName] as CacheManager;
            if (cacheManager != null)
            {
                return cacheManager;
            }

            CachingConfigurationView view = new CachingConfigurationView(ConfigurationContext);
            CacheManagerData cacheManagerData = view.GetCacheManagerData(cacheManagerName);
            CacheCapacityScavengingPolicy scavengingPolicy =
                new CacheCapacityScavengingPolicy(cacheManagerName, view);

            IBackingStore backingStore = backingStoreFactory.CreateBackingStore(cacheManagerName);
            Cache cache = new Cache(backingStore, scavengingPolicy);

            ExpirationPollTimer timer = new ExpirationPollTimer();
            ExpirationTask expirationTask = CreateExpirationTask(cache);
            ScavengerTask scavengerTask = new ScavengerTask(cacheManagerName, view, scavengingPolicy, cache);
            BackgroundScheduler scheduler = new BackgroundScheduler(expirationTask, scavengerTask);
            cache.Initialize(scheduler);

            scheduler.Start();
            timer.StartPolling(new TimerCallback(scheduler.ExpirationTimeoutExpired), cacheManagerData.ExpirationPollFrequencyInSeconds * 1000);

            cacheManager = new CacheManager(cache, scheduler, timer);
            cacheManagers.Add(cacheManagerName, cacheManager);
            return cacheManager;
        }