Beispiel #1
0
        public AsyncCache(ILog log, MetricsContext metrics, IDateTime dateTime, IRevokeListener revokeListener, Func <CacheConfig> getRevokeConfig)
        {
            DateTime        = dateTime;
            GetRevokeConfig = getRevokeConfig;
            Log             = log;

            // ReSharper disable once ConditionIsAlwaysTrueOrFalse
            if (ObjectCache.Host == null &&
                Interlocked.CompareExchange(ref oneTime, 1, 0) == 0)
            {
                ObjectCache.Host = this;
            }
            else
            {
                Log.Error("AsyncCache: Failed to register with ObjectCache.Host since it was already registered. Cache memory size will not be reported to Metrics.NET. Please make sure AsyncCache is singleton to prevent this issue.");
            }

            Clear();

            Metrics = metrics;
            InitMetrics();
            var onRevoke = new ActionBlock <string>(OnRevoke);

            RevokeDisposable = revokeListener.RevokeSource.LinkTo(onRevoke);
        }
        public void Setup()
        {
            SetupServiceMock();
            SetupDateTime();
            _revokeDelay = Task.Delay(0);

            _proxy          = _kernel.Get <ICachingTestService>();
            _cacheRevoker   = _kernel.Get <ICacheRevoker>();
            _revokeListener = _kernel.Get <IRevokeListener>();
        }
Beispiel #3
0
 public void SetUp()
 {
     this.subLog                  = Substitute.For <ILog>();
     this.subRevokeListener       = Substitute.For <IRevokeListener>();
     this.subRevokeKeyIndexer     = Substitute.For <IRevokeKeyIndexer>();
     this.subFuncRevokeKeyIndexer = Substitute.For <IRevokeKeyIndexerFactory>();
     subFuncRevokeKeyIndexer.Create().Returns(_ => subRevokeKeyIndexer);
     this.subFuncRevokeNotifierConfig = () => new RevokeNotifierConfig {
         CleanupIntervalInSec = 1
     };
 }
        public RevokeNotifier(ILog logger,
                              IRevokeListener revokeListener,
                              IRevokeKeyIndexerFactory indexerFactory,
                              Func <RevokeNotifierConfig> configFunc)
        {
            _logger        = logger;
            _revokeIndexer = indexerFactory.Create();
            ITargetBlock <string> actionBlock = new ActionBlock <string>(OnRevoke); //TODO: move to new class

            _configFunc = configFunc;
            var config = _configFunc();

            _timerInterval = config.CleanupIntervalInSec;
            var ts = TimeSpan.FromSeconds(_timerInterval);

            _timer = new Timer(RevokeNotifierTimerCallback, null, ts, ts);
            revokeListener.RevokeSource.LinkTo(actionBlock);
        }
Beispiel #5
0
        public AsyncCache(ILog log, IDateTime dateTime, IRevokeListener revokeListener, Func <CacheConfig> getRevokeConfig)
        {
            DateTime        = dateTime;
            GetRevokeConfig = getRevokeConfig;
            Log             = log;

            if (ObjectCache.Host == null)
            {
                ObjectCache.Host = this;
            }
            else
            {
                Log.Error("AsyncCache: Failed to register with ObjectCache.Host since it was already registered. Cache memory size will not be reported to Metrics.NET. Please make sure AsyncCache is singleton to prevent this issue.");
            }

            Clear();

            var onRevoke = new ActionBlock <string>(OnRevoke);

            RevokeDisposable = revokeListener.RevokeSource.LinkTo(onRevoke);
        }