Exemplo n.º 1
0
        private void button1_Click(object sender, EventArgs e)
        {
            var applicationContainer = new BlockContainer();
            BlockRegister.Initialize(applicationContainer);
            var cachingBlock = new CachingBlock();

            BlockRegister.RegisterInstance<CachingBlock>(cachingBlock);

            var mBackingStore = new NullBackingStore();
            var mInstrumentationProvider = new NullCachingInstrumentationProvider();
            var dataCache = new Cache(mBackingStore, mInstrumentationProvider);
            var mExpirationTask = new ExpirationTask(dataCache, mInstrumentationProvider);
            var mScavengerTask = new ScavengerTask(1, 5, dataCache, mInstrumentationProvider);
            var mBackgroundScheduler = new BackgroundScheduler(mExpirationTask, mScavengerTask, mInstrumentationProvider);
            var mExpirationPollTimer = new ExpirationPollTimer(1000);
            var dataCacheManager = new CacheManager(dataCache, mBackgroundScheduler, mExpirationPollTimer);

            var mCachingBlock = BlockRegister.GetInstance<CachingBlock>();
            mCachingBlock.RegisterInstance("MyApplicationCache", dataCacheManager);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Создание кэш-менеджера, сохраняющего в памяти с пустым инструментарием
        /// </summary>
        /// <param name="numberToRemoveWhenScavenging">Число удаляемых элементов.</param>
        /// <param name="maximumElementsInCacheBeforeScavenging">Максимальное количество элементов до сбора.</param>
        /// <param name="expirationPollFrequencyInMilliSeconds">Временной интервал проверки ограничений (мс).</param>
        public CacheManager(int numberToRemoveWhenScavenging, int maximumElementsInCacheBeforeScavenging, int expirationPollFrequencyInMilliSeconds)
        {
            var mBackingStore = new NullBackingStore();
            var mInstrumentationProvider = new NullCachingInstrumentationProvider();
            var dataCache = new Cache(mBackingStore, mInstrumentationProvider);

            realCache = dataCache;

            var mExpirationPollTimer = new ExpirationPollTimer(expirationPollFrequencyInMilliSeconds);

            pollTimer = mExpirationPollTimer;

            var mExpirationTask = new ExpirationTask(dataCache, mInstrumentationProvider);
            var mScavengerTask = new ScavengerTask(numberToRemoveWhenScavenging, maximumElementsInCacheBeforeScavenging, dataCache, mInstrumentationProvider);
            var mBackgroundScheduler = new BackgroundScheduler(mExpirationTask, mScavengerTask, mInstrumentationProvider);

            backgroundScheduler = mBackgroundScheduler;

            pollTimer.StartPolling(backgroundScheduler.ExpirationTimeoutExpired);
        }