Exemplo n.º 1
0
        private ICache DecorateWithStatistics(ICache cache)
        {
            var builder = new CacheDecoratorChainBuilder();

            cache = builder.AddDecorators(cache,
                                          new CacheDecoratorOptions
            {
                IsStatisticsOn = true,
                Statistics     = _cacheStatisticsFactory()
            });
            return(cache);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Unregisters the <paramref name="cache"/> from this administator
        /// </summary>
        /// <returns>
        /// The <paramref name="cache"/> minus <see cref="IStatisticsCache"/> behaviour previously added by this administrator
        /// </returns>
        /// <remarks>
        /// Any <see cref="IStatisticsCache"/> behaviour added to the <paramref name="cache"/> when it was registered
        /// with this administrator will be removed
        /// </remarks>
        public virtual ICache Unregister(ICache cache)
        {
            bool removeStatistics;
            bool found = _allCaches.TryRemove(cache, out removeStatistics);

            if (found && removeStatistics)
            {
                var chainBuilder = new CacheDecoratorChainBuilder();
                return(chainBuilder.RemoveDecorators(cache, new CacheDecoratorOptions {
                    IsStatisticsOn = false
                }));
            }
            else
            {
                return(cache);
            }
        }