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 bool ContainsValidBackoffEntry(ExactTimeoutCache <string, DateTime> timeoutCache, string emailAddress) { DateTime t; return(timeoutCache.TryGetValue(emailAddress, out t) && t > DateTime.UtcNow); }