private void RegisterDescriptorCache(IWindsorContainer container)
        {
            var absoluteExpirationPeriod = TimeSpan.FromSeconds(
                Convert.ToInt32(_configValueProvider.GetValue(DescriptorCacheAbsoluteExpirationSecondsKey) ?? "60"));

            var cacheProvider = new ExpiringConcurrentDictionaryCacheProvider(absoluteExpirationPeriod);

            container.Register(
                Component.For <IDescriptorsCache>()
                .ImplementedBy <DescriptorsCache>()
                .DependsOn(Dependency.OnValue <ICacheProvider>(cacheProvider)));
        }
        protected virtual void RegisterIDescriptorCache(IWindsorContainer container)
        {
            var absoluteExpirationPeriod = TimeSpan.FromMinutes(30);

            var cacheProvider = new ExpiringConcurrentDictionaryCacheProvider(absoluteExpirationPeriod);

            container.Register(
                Component.For <IDescriptorsCache>()
                .ImplementedBy <DescriptorsCache>()
                .DependsOn(Dependency.OnValue <ICacheProvider>(cacheProvider)));

            IDescriptorsCache cache = null;

            // Provide cache using a closure rather than repeated invocations to the container
            DescriptorsCache.GetCache = () => cache ?? (cache = container.Resolve <IDescriptorsCache>());
        }
Beispiel #3
0
            protected override void Act()
            {
                const int TestExpirationPeriod = 250;

                var cache = new ExpiringConcurrentDictionaryCacheProvider(TimeSpan.FromMilliseconds(TestExpirationPeriod));

                // Wait for midpoint of the first expiration period
                Thread.Sleep(TestExpirationPeriod / 2);

                // Iterate through initial settings and 2 cache expirations
                for (int i = 0; i < 3; i++)
                {
                    object value;

                    // Try to get items (should NOT be there)
                    _actualGetResultsForCacheMiss.Add(cache.TryGetCachedObject("Initial-SetCachedObject1", out value));
                    _actualEntriesForCacheMiss.Add(value);

                    _actualGetResultsForCacheMiss.Add(cache.TryGetCachedObject("Initial-SetCachedObject2", out value));
                    _actualEntriesForCacheMiss.Add(value);

                    // Add new items
                    cache.SetCachedObject("Initial-SetCachedObject1", _suppliedEntries[0]);
                    cache.Insert("Initial-SetCachedObject2", _suppliedEntries[1], DateTime.MaxValue, TimeSpan.Zero);

                    // Try to get items (should STILL be there)
                    _actualGetResultsForCacheHit.Add(cache.TryGetCachedObject("Initial-SetCachedObject1", out value));
                    _actualEntriesForCacheHit.Add(value);

                    _actualGetResultsForCacheHit.Add(cache.TryGetCachedObject("Initial-SetCachedObject2", out value));
                    _actualEntriesForCacheHit.Add(value);

                    // Let the cache expire (and continue midway through next expiration period)
                    Thread.Sleep(TestExpirationPeriod);
                }
            }