Пример #1
0
        public void SetMany(ReadOnlySpan <KeyValuePair <TKey, TValue> > values, TimeSpan timeToLive)
        {
            CheckDisposed();

            var nowTicks = TicksHelper.GetTicks64();

            foreach (var value in values)
            {
                SetImpl(value.Key, value.Value, timeToLive, nowTicks);
            }
        }
Пример #2
0
        public void Mark(string key)
        {
            var now = TicksHelper.GetTicks64();

            if (!_dictionary.TryAdd(key, now))
            {
                return;
            }

            _queue.Enqueue(new KeyValuePair <string, long>(key, now));
        }
Пример #3
0
        public int GetMany(ReadOnlySpan <TKey> keys, Span <KeyValuePair <TKey, TValue> > destination)
        {
            CheckDisposed();

            if (destination.Length < keys.Length)
            {
                throw Errors.LocalCache_DestinationArrayTooSmall(nameof(destination));
            }

            var countFound = 0;
            var nowTicks   = TicksHelper.GetTicks64();

            foreach (var key in keys)
            {
                if (TryGetImpl(key, nowTicks, out var value))
                {
                    destination[countFound++] = new KeyValuePair <TKey, TValue>(key, value);
                }
            }

            return(countFound);
        }
Пример #4
0
        public void Set(TKey key, TValue value, TimeSpan timeToLive)
        {
            CheckDisposed();

            SetImpl(key, value, timeToLive, TicksHelper.GetTicks64());
        }
Пример #5
0
        public bool TryGet(TKey key, out TValue value)
        {
            CheckDisposed();

            return(TryGetImpl(key, TicksHelper.GetTicks64(), out value));
        }
Пример #6
0
        private bool IsRecent(long timestamp)
        {
            var age = TicksHelper.GetTicks64() - timestamp;

            return(age < _recentWindow);
        }