private TCacheEntry GetClient <TCacheEntry, TKey>(ExactTimeoutCache <Guid, TCacheEntry> cache, TKey key, Func <TCacheEntry> createNewEntry) where TCacheEntry : CachedClient where TKey : DirectoryObject { TCacheEntry tcacheEntry; if (cache.TryGetValue(key.Guid, out tcacheEntry)) { if (tcacheEntry.IsValid) { this.logger.Log(MigrationEventType.Instrumentation, "Returning cached {0} client for {1}", new object[] { typeof(TCacheEntry).Name, key.Name }); tcacheEntry.IncrementReferenceCount(); return(tcacheEntry); } cache.Remove(key.Guid); } this.logger.Log(MigrationEventType.Instrumentation, "Creating new {0} client for {1}", new object[] { typeof(TCacheEntry).Name, key.Name }); tcacheEntry = createNewEntry(); cache.TryInsertSliding(key.Guid, tcacheEntry, this.cacheDuration); tcacheEntry.IncrementReferenceCount(); return(tcacheEntry); }
private static void SetNumberAndPercentCounters(ExactTimeoutCache <BudgetKey, BudgetKey> cache, ExPerformanceCounter numberCounter, ExPerformanceCounter percentCounter) { if (!ThrottlingPerfCounterWrapper.PerfCountersInitialized) { return; } int budgetCount = ThrottlingPerfCounterWrapper.GetBudgetCount(); int count = cache.Count; numberCounter.RawValue = (long)count; int num = (budgetCount == 0) ? 0 : (100 * count / budgetCount); if (num > 100) { num = 100; } percentCounter.RawValue = (long)num; }
private bool ContainsValidBackoffEntry(ExactTimeoutCache <string, DateTime> timeoutCache, string emailAddress) { DateTime t; return(timeoutCache.TryGetValue(emailAddress, out t) && t > DateTime.UtcNow); }