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 }
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); }
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); }
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 }); }
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(); }
public TResult GetOrAdd(TKey key, TResult lazyTask, EntryOptions options) => GetOrAdd(key, lazyTask);
public void Set(TKey key, TResult value, EntryOptions options) => Set(key, value);
public void Set(TKey key, TValue value, EntryOptions options) => Set(key, value);
public TValue GetOrAdd(TKey key, TValue lazyTask, EntryOptions options) => GetOrAdd(key, lazyTask);
public void Set(TKey key, TValue value, EntryOptions options) { }
public TValue GetOrAdd(TKey key, TValue lazyTask, EntryOptions options) { return(lazyTask); }