Beispiel #1
0
        public void LruCacheStorage_Gauntlet_RemoveByPolicy()
        {
            var cacheSize   = 16;
            var uniqueCount = 32;
            var rootedCount = 256;
            var repeat      = 10;

            var cache   = new Cache <string>(new LruCacheStorage <string>(cacheSize));
            var strings = Enumerable.Range(1, uniqueCount).Select(x => "string" + x).ToArray();
            var refs    = new IDiscardable <string> [rootedCount];
            var rand    = new Random(17);
            var tests   = Enumerable.Repeat(strings, rootedCount * repeat).SelectMany(ss => ss).Select(s => Copy(s)).OrderBy(_ => rand.Next());

            var count = 0;

            Parallel.ForEach(
                tests,
                test =>
            {
                var r = cache.Create(test);
                refs[Interlocked.Increment(ref count) % rootedCount] = r;
                Assert.AreEqual(test, r.Value);
            }
                );
        }
Beispiel #2
0
        /// <summary>
        /// Creates a new quoted value using the specified expression tree.
        /// </summary>
        /// <param name="value">Value of the quote.</param>
        /// <param name="expression">Expression representing the quoted value.</param>
        /// <param name="policy">Policy used to evaluate the expression.</param>
        public Quoted(T value, Expression expression, IExpressionEvaluationPolicy policy)
        {
            if (expression == null)
            {
                throw new ArgumentNullException(nameof(expression));
            }

            if (policy == null)
            {
                throw new ArgumentNullException(nameof(policy));
            }

            if (!typeof(T).IsAssignableFrom(expression.Type))
            {
                throw new ArgumentException("The specified expression does not have a type compatible with the specified value.", nameof(expression));
            }

            Value       = value;
            _expression = policy.InMemoryCache.Create(expression);
        }