public void TestQueryAsyncWithOptions()
        {
            var delayTime = TimeSpan.FromMilliseconds(100);
            var executor  = CreateMemoryExecutor(delayTime);

            var query = new AddQuery {
                Left = 1, Right = 2
            };

            var options = new EntryOptions {
                SlidingExpiration = TimeSpan.FromMinutes(1)
            };

            Assert.True(
                TimeCost(async() => { Assert.Equal(3, await executor.QueryAsync(query, options)); })
                >=
                delayTime);

            Assert.True(
                TimeCost(async() => { Assert.Equal(3, await executor.QueryAsync(query, options)); })
                <=
                TimeSpan.FromMilliseconds(50), "Should hit cache");  //well, a cache hit

            Assert.True(
                TimeCost(async() => { Assert.Equal(3, await executor.QueryAsync(query)); })
                <=
                TimeSpan.FromMilliseconds(50), "Should hit cache");  //well, a cache hit
        }
Ejemplo n.º 2
0
        public static string CatchVariableName(ITreeNode treeNode, IDeclaredType exceptionType)
        {
            var namingPolicyManager   = new NamingPolicyManager(LanguageManager.Instance, treeNode.GetSolution());
            var nameParser            = new NameParser(treeNode.GetSolution(), namingPolicyManager, new HostCulture());
            var nameSuggestionManager = new NameSuggestionManager(treeNode.GetSolution(), nameParser, namingPolicyManager);
            var policy = namingPolicyManager.GetPolicy(NamedElementKinds.Locals, treeNode.Language, treeNode.GetSourceFile());

            var namesCollection = nameSuggestionManager.CreateEmptyCollection(
                PluralityKinds.Single, treeNode.Language, true, treeNode.GetSourceFile());

            var entryOptions = new EntryOptions
            {
                PluralityKind          = PluralityKinds.Single,
                PredefinedPrefixPolicy = PredefinedPrefixPolicy.Preserve,
                Emphasis      = Emphasis.Good,
                SubrootPolicy = SubrootPolicy.Decompose
            };

            namesCollection.Add(exceptionType, entryOptions);
            namesCollection.Prepare(policy.NamingRule, ScopeKind.Common, new SuggestionOptions());

            try
            {
                return(namesCollection.GetRoots().FirstOrDefault()?.GetFinalPresentation() ?? String.Empty);
            }
            catch (ArgumentNullException)
            {
                return(String.Empty);
            }
        }
        public void TestCustomOptions4()
        {
            var delayTime = TimeSpan.FromMilliseconds(200);
            var executor  = CreateMemoryExecutor(delayTime);

            var query = new AddQuery {
                Left = 1, Right = 2
            };

            var options = new EntryOptions {
                AbsoluteExpiration = DateTimeOffset.Now.AddMilliseconds(1)
            };

            Assert.True(
                TimeCost(async() => { Assert.Equal(3, await executor.QueryAsync(query, options)); })
                >=
                delayTime);

            Thread.Sleep(1);

            Assert.True(
                TimeCost(async() => { Assert.Equal(3, await executor.QueryAsync(query, options)); })
                >=
                delayTime);
        }
Ejemplo n.º 4
0
        public void TestNewOptions()
        {
            var options = new EntryOptions();

            Assert.Equal(options.Behaviors, EntryBehaviors.Default);

            Assert.Null(options.AbsoluteExpiration);
            Assert.Null(options.AbsoluteExpirationRelativeToNow);
            Assert.Null(options.SlidingExpiration);
        }
Ejemplo n.º 5
0
        public void TestNewOptions()
        {
            var options = new EntryOptions();

            Assert.Equal(options.Behaviors, EntryBehaviors.Default);

            Assert.Null(options.AbsoluteExpiration);
            Assert.Null(options.AbsoluteExpirationRelativeToNow);
            Assert.Null(options.SlidingExpiration);
        }
Ejemplo n.º 6
0
        public void Set(TKey key, TValue value, EntryOptions options)
        {
            string serializeKey = GetSerializeKey(key);

            _memoryCache.Set(serializeKey, value, new MemoryCacheEntryOptions
            {
                AbsoluteExpiration = options.AbsoluteExpiration,
                AbsoluteExpirationRelativeToNow = options.AbsoluteExpirationRelativeToNow,
                SlidingExpiration = options.SlidingExpiration
            });
        }
Ejemplo n.º 7
0
        public TValue GetOrAdd(TKey key, TValue lazyTask, EntryOptions options)
        {
            string serializeKey = GetSerializeKey(key);
            TValue result;

            if (!_memoryCache.TryGetValue(serializeKey, out result))
            {
                result = lazyTask;
                var memoryEntryOptions = new MemoryCacheEntryOptions
                {
                    AbsoluteExpiration = options.AbsoluteExpiration,
                    AbsoluteExpirationRelativeToNow = options.AbsoluteExpirationRelativeToNow,
                    SlidingExpiration = options.SlidingExpiration,
                };
                _memoryCache.Set(serializeKey, result, memoryEntryOptions);
            }
            return(result);
        }
        public static string CatchVariableName(ITreeNode treeNode, IDeclaredType exceptionType)
        {
            var namingPolicyManager = new NamingPolicyManager(LanguageManager.Instance, treeNode.GetSolution());
            var nameParser = new NameParser(treeNode.GetSolution(), namingPolicyManager);
            var nameSuggestionManager = new NameSuggestionManager(treeNode.GetSolution(), nameParser, namingPolicyManager);
            var policy = namingPolicyManager.GetPolicy(NamedElementKinds.Locals, treeNode.Language, treeNode.GetSourceFile());

            var namesCollection = nameSuggestionManager.CreateEmptyCollection(
                PluralityKinds.Single, treeNode.Language, true, treeNode.GetSourceFile());

            var entryOptions = new EntryOptions
            {
                PluralityKind = PluralityKinds.Single,
                PredefinedPrefixPolicy = PredefinedPrefixPolicy.Preserve,
                Emphasis = Emphasis.Good,
                SubrootPolicy = SubrootPolicy.Decompose
            };

            namesCollection.Add(exceptionType, entryOptions);
            namesCollection.Prepare(policy.NamingRule, ScopeKind.Common, new SuggestionOptions());

            return namesCollection.FirstName();
        }
Ejemplo n.º 9
0
 public TResult GetOrAdd(TKey key, TResult lazyTask, EntryOptions options) => GetOrAdd(key, lazyTask);
Ejemplo n.º 10
0
 public void Set(TKey key, TResult value, EntryOptions options) => Set(key, value);
Ejemplo n.º 11
0
 public void Set(TKey key, TValue value, EntryOptions options) => Set(key, value);
Ejemplo n.º 12
0
 public TValue GetOrAdd(TKey key, TValue lazyTask, EntryOptions options) => GetOrAdd(key, lazyTask);
Ejemplo n.º 13
0
 public void Set(TKey key, TValue value, EntryOptions options)
 {
 }
Ejemplo n.º 14
0
 public TValue GetOrAdd(TKey key, TValue lazyTask, EntryOptions options)
 {
     return(lazyTask);
 }