protected void CacheUpdateFromSavedObject(IConfigurable instance, ObjectState objectStateBeforeSave) { ADRawEntry adrawEntry = instance as ADRawEntry; bool flag = Configuration.IsCacheEnabledForInsertOnSave(adrawEntry); ExTraceGlobals.SessionTracer.TraceDebug((long)this.GetHashCode(), "UpdateOrRemoveFromCache. Identity={0}, ObjectStateBeforeSave={1}, DistinguishedName={2}, WhenCreatedUtc={3}, InsertInCache={4}", new object[] { instance.Identity, objectStateBeforeSave, (adrawEntry != null) ? adrawEntry.GetDistinguishedNameOrName() : "<NULL>", (adrawEntry != null) ? adrawEntry[ADObjectSchema.WhenCreatedUTC] : "<NULL>", flag }); if (!flag) { if (objectStateBeforeSave != ObjectState.New) { this.CacheDelete(instance); } return; } IEnumerable <PropertyDefinition> objectProperties = null; if (!(adrawEntry is ADObject)) { objectProperties = new List <PropertyDefinition>(0); } this.CacheInsert <ADRawEntry>(adrawEntry, null, objectProperties); }
private void CacheDeleteInternal(IConfigurable instance) { string error = null; Stopwatch stopwatch = Stopwatch.StartNew(); CachePerformanceTracker.StartLogging(); bool isNewProxyObject = false; int retryCount = 0; string callerInfo = null; Guid activityId = Guid.Empty; try { TSession tsession = this.GetCacheSession(); tsession.Delete(instance); CacheDirectorySession cacheDirectorySession = this.GetCacheSession() as CacheDirectorySession; if (cacheDirectorySession != null) { isNewProxyObject = cacheDirectorySession.IsNewProxyObject; retryCount = cacheDirectorySession.RetryCount; } TSession session = this.GetSession(); if (session.ActivityScope != null) { TSession session2 = this.GetSession(); if (session2.ActivityScope.Status == ActivityContextStatus.ActivityStarted) { TSession session3 = this.GetSession(); activityId = session3.ActivityScope.ActivityId; } } TSession session4 = this.GetSession(); callerInfo = session4.CallerInfo; } catch (Exception ex) { error = ex.ToString(); throw; } finally { stopwatch.Stop(); string cachePerformanceTracker = CachePerformanceTracker.StopLogging(); ADRawEntry adrawEntry = instance as ADRawEntry; CacheProtocolLog.BeginAppend("Remove", (adrawEntry != null) ? adrawEntry.GetDistinguishedNameOrName() : "<NULL>", DateTime.MinValue, stopwatch.ElapsedMilliseconds, -1L, stopwatch.ElapsedMilliseconds, -1L, -1L, isNewProxyObject, retryCount, instance.GetType().Name, cachePerformanceTracker, activityId, callerInfo, error); } }
private void CacheInsert <TResult>(TResult instance, Func <TResult, List <Tuple <string, KeyType> > > getAdditionalKeys = null, IEnumerable <PropertyDefinition> objectProperties = null) where TResult : IConfigurable, new() { ArgumentValidator.ThrowIfNull("query", instance); Stopwatch stopwatch = Stopwatch.StartNew(); CachePerformanceTracker.StartLogging(); bool isNewProxyObject = false; int retryCount = 0; Guid activityId = Guid.Empty; string callerInfo = null; string error = null; try { List <Tuple <string, KeyType> > keys = null; TSession session = this.GetSession(); if (session.ActivityScope != null) { TSession session2 = this.GetSession(); if (session2.ActivityScope.Status == ActivityContextStatus.ActivityStarted) { TSession session3 = this.GetSession(); activityId = session3.ActivityScope.ActivityId; } } TSession session4 = this.GetSession(); callerInfo = session4.CallerInfo; if (getAdditionalKeys != null) { keys = getAdditionalKeys(instance); } ICacheDirectorySession cacheDirectorySession = this.GetCacheSession() as ICacheDirectorySession; bool flag = false; if (((IDirectorySession)this).SessionSettings.TenantConsistencyMode == TenantConsistencyMode.IgnoreRetiredTenants && (TenantRelocationStateCache.IsTenantRetired((ADObjectId)instance.Identity) || TenantRelocationStateCache.IsTenantArriving((ADObjectId)instance.Identity))) { ExTraceGlobals.SessionTracer.TraceWarning <ObjectId>((long)this.GetHashCode(), "CacheInsert. DN {0}. Tenant Is Retired or Arriving, skipping.", instance.Identity); } else { if (!instance.GetType().Equals(CompositeDirectorySession <TSession> .ExchangeConfigUnitCUType) && (TenantRelocationStateCache.IsTenantLockedDown((ADObjectId)instance.Identity) || TenantRelocationStateCache.IsTenantRetired((ADObjectId)instance.Identity))) { flag = true; } int num = flag ? 30 : Configuration.GetCacheExpirationForObject(instance as ADRawEntry); CacheItemPriority cacheItemPriority = flag ? CacheItemPriority.Default : Configuration.GetCachePriorityForObject(instance as ADRawEntry); if (cacheDirectorySession != null) { cacheDirectorySession.Insert(instance, objectProperties, keys, num, cacheItemPriority); } else { TSession tsession = this.GetCacheSession(); tsession.Save(instance); } CacheDirectorySession cacheDirectorySession2 = this.GetCacheSession() as CacheDirectorySession; if (cacheDirectorySession2 != null) { isNewProxyObject = cacheDirectorySession2.IsNewProxyObject; retryCount = cacheDirectorySession2.RetryCount; } ExTraceGlobals.SessionTracer.TraceDebug((long)this.GetHashCode(), "CacheInsert. DN={0}, IsTenantLockedDownOrRetired={1}, CacheExpiration={2}, Priority={3}", new object[] { instance.Identity, flag, num, cacheItemPriority }); } } catch (TransientException ex) { ExTraceGlobals.SessionTracer.TraceError <ObjectId, TransientException>((long)this.GetHashCode(), "CacheInsert. DN {0}. Exception {1}", instance.Identity, ex); error = ex.ToString(); } catch (Exception ex2) { error = ex2.ToString(); throw; } finally { stopwatch.Stop(); string cachePerformanceTracker = CachePerformanceTracker.StopLogging(); ADRawEntry adrawEntry = instance as ADRawEntry; CacheProtocolLog.BeginAppend("Save", (adrawEntry != null) ? adrawEntry.GetDistinguishedNameOrName() : "<NULL>", DateTime.MinValue, stopwatch.ElapsedMilliseconds, -1L, -1L, stopwatch.ElapsedMilliseconds, -1L, isNewProxyObject, retryCount, instance.GetType().Name, cachePerformanceTracker, activityId, callerInfo, error); } }