コード例 #1
0
        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
        }
コード例 #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);
            }
        }
コード例 #3
0
        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);
        }
コード例 #4
0
ファイル: TestEntryOptions.cs プロジェクト: karldodd/DotQuery
        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);
        }
コード例 #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);
        }
コード例 #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
            });
        }
コード例 #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);
        }
コード例 #8
0
        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();
        }
コード例 #9
0
 public TResult GetOrAdd(TKey key, TResult lazyTask, EntryOptions options) => GetOrAdd(key, lazyTask);
コード例 #10
0
 public void Set(TKey key, TResult value, EntryOptions options) => Set(key, value);
コード例 #11
0
 public void Set(TKey key, TValue value, EntryOptions options) => Set(key, value);
コード例 #12
0
 public TValue GetOrAdd(TKey key, TValue lazyTask, EntryOptions options) => GetOrAdd(key, lazyTask);
コード例 #13
0
ファイル: EmptyQueryCache.cs プロジェクト: thedeveus/DotQuery
 public void Set(TKey key, TValue value, EntryOptions options)
 {
 }
コード例 #14
0
ファイル: EmptyQueryCache.cs プロジェクト: thedeveus/DotQuery
 public TValue GetOrAdd(TKey key, TValue lazyTask, EntryOptions options)
 {
     return(lazyTask);
 }