コード例 #1
0
        public int GetMany(ReadOnlySpan <TKey> keys, Span <KeyValuePair <TKey, TValue> > destination)
        {
            Interlocked.Increment(ref GetManyExecutionCount);

            if (_throwExceptionOnNextAction)
            {
                _throwExceptionOnNextAction = false;
                throw new Exception();
            }

            var countFound = _innerCache.GetMany(keys, destination);

            var hits   = countFound;
            var misses = keys.Length - countFound;

            if (hits > 0)
            {
                Interlocked.Add(ref HitsCount, hits);
            }
            if (misses > 0)
            {
                Interlocked.Add(ref MissesCount, misses);
            }

            return(countFound);
        }
コード例 #2
0
        public int GetMany(ReadOnlySpan <TKey> keys, Span <KeyValuePair <TKey, TValue> > destination)
        {
            var stopwatch = StopwatchStruct.StartNew();

            try
            {
                var countFound = _innerCache.GetMany(keys, destination);

                var values = destination.Slice(0, countFound);

                OnGetManyCompletedSuccessfully(keys, values, stopwatch.Elapsed);

                return(countFound);
            }
            catch (Exception ex)
            {
                OnGetManyException(keys, stopwatch.Elapsed, ex, out var exceptionHandled);

                if (!exceptionHandled)
                {
                    throw;
                }

                return(0);
            }
        }
コード例 #3
0
        public static KeyValuePair <TKey, TValue>[] GetMany <TKey, TValue>(
            this ILocalCache <TKey, TValue> cache,
            ReadOnlySpan <TKey> keys)
        {
            using var memoryOwner = MemoryPool <KeyValuePair <TKey, TValue> > .Shared.Rent(keys.Length);

            var span = memoryOwner.Memory.Span;

            var countFound = cache.GetMany(keys, span);

            return(span.Slice(0, countFound).ToArray());
        }