Exemplo n.º 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));
        }
        /// <summary>
        /// 
        /// </summary>
        /// <param name="realCache"></param>
        /// <param name="backgroundScheduler"></param>
        /// <param name="pollTimer"></param>
        public CacheManager(Cache realCache, BackgroundScheduler backgroundScheduler, ExpirationPollTimer pollTimer)
		{
            if (pollTimer == null) throw new ArgumentNullException("pollTimer");

			this.realCache = realCache;
			this.pollTimer = pollTimer;
            this.backgroundScheduler = backgroundScheduler;


            pollTimer.StartPolling(backgroundScheduler.ExpirationTimeoutExpired);
		}
        /// <summary>
        ///
        /// </summary>
        /// <param name="realCache"></param>
        /// <param name="backgroundScheduler"></param>
        /// <param name="pollTimer"></param>
        public CacheManager(Cache realCache, BackgroundScheduler backgroundScheduler, ExpirationPollTimer pollTimer)
        {
            if (pollTimer == null)
            {
                throw new ArgumentNullException("pollTimer");
            }

            this.realCache           = realCache;
            this.pollTimer           = pollTimer;
            this.backgroundScheduler = backgroundScheduler;


            pollTimer.StartPolling(backgroundScheduler.ExpirationTimeoutExpired);
        }
Exemplo n.º 5
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);
        }
Exemplo n.º 6
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;
        }