Пример #1
0
        public ICollection <byte[]> PutItems(ICollection <CacheValue> items)
        {
            _lock.EnterWriteLock();
            try
            {
                var now = DateTime.UtcNow;
                if (_expireCacheChunk < now)
                {
                    var curr = _previous;
                    _previous = _current;
                    _current  = curr;
                    _current.Clear();
                    _expireCacheChunk = now + _expireTimeChunk;
                }

                var expiredKeys = new HashSet <byte[]>(_expiredKeys.Reset(), new ByteArrayComparer());

                if (items.Count > 0)
                {
                    foreach (var item in items)
                    {
                        _current[item.Key] = new CacheItem()
                        {
                            Expired = now.AddSeconds(item.ExpiredAtSeconds), Payload = item.Value
                        };
                        expiredKeys.Remove(item.Key);
                    }

                    OnItems.Invoke(items);
                }

                return(expiredKeys);
            }
            finally { _lock.ExitWriteLock(); }
        }