private bool DoGetOrAdd(OperationEvent operEvent) { CacheItem ci = operEvent.OperObject as CacheItem; if (ci == null) { LogManager.Warn("CacheManager:Assert Failure", "DoGetOrAdd a null item"); return true; } //Cache Item bool added = m_cacheItems.TryAdd(ci.Key, ci); if (added) { //Add the SchedulerKey at the same time SchedulerKey sk = new SchedulerKey(ci.NextExpirationTime, ci.Key); if (m_heap.ContainsKey(sk)) { //This should not happen. If it does, then this is a critial bug! LogManager.Warn("CacheManager:Assert Failure", string.Format("The SchedulerKey key[{0}] is already exising", sk.ToString())); } else { m_heap.Add(sk, DUMMY); } operEvent.OperResult = ci; LogManager.Info("CacheManager:DoGetOrAdd", string.Format("The key [{0}] is added, value=[{1}]", ci.Key, ci.ToString())); } else { CacheItem existingItem = null; if (!m_cacheItems.TryGetValue(ci.Key, out existingItem)) { //This should not happen. If it does, then this is a critial bug! LogManager.Warn("CacheManager:Assert Failure", string.Format("The expected existing key[{0}] doesn't exist", ci.Key)); } else if (existingItem == null) { //This should not happen. If it does, then this is a critial bug! LogManager.Warn("CacheManager:Assert Failure", string.Format("The expected existing key[{0}] is null", ci.Key)); } else { operEvent.OperResult = existingItem; //LogManager.Debug("CacheManager:DoGetOrAdd", string.Format("The key [{0}] is already existing, value=[{1}]", // ci.Key, existingItem.ToString())); } } return true; }
private bool DoRemove(CacheItem ci) { if (ci == null) { LogManager.Warn("CacheManager:Assert Failure", "DoRemove a null item"); return true; } CacheItem value = null; if (!m_cacheItems.TryRemove(ci.Key, out value)) { LogManager.Warn("CacheManager:DoRemove", string.Format("The CacheItem key[{0}] is already removed", ci.Key)); } SchedulerKey sk = new SchedulerKey(ci.NextExpirationTime, ci.Key); if (!m_heap.ContainsKey(sk)) { LogManager.Warn("CacheManager:DoRemove", string.Format("The SchedulerKey key[{0}] is already removed", sk.ToString())); } else { m_heap.Remove(sk); } LogManager.Info("CacheManager:DoRemove", string.Format("The key [{0}] is removed", ci.Key)); return true; }
private bool DoAdd(CacheItem ci) { if (ci == null) { LogManager.Warn("CacheManager:Assert Failure", "DoAdd a null item"); return true; } //Cache Item bool added = m_cacheItems.TryAdd(ci.Key, ci); if (added) { //Add the SchedulerKey at the same time SchedulerKey sk = new SchedulerKey(ci.NextExpirationTime, ci.Key); if (m_heap.ContainsKey(sk)) { //This should not happen. If it does, then this is a critial bug! LogManager.Warn("CacheManager:Assert Failure", string.Format("The SchedulerKey key[{0}] is already exising", sk.ToString())); } else { m_heap.Add(sk, DUMMY); } } if (added) { LogManager.Info("CacheManager:DoAdd", string.Format("The key [{0}] is added, value=[{1}]", ci.Key, ci.ToString())); } else { LogManager.Info("CacheManager:DoAdd", string.Format("The key [{0}] is already existing", ci.Key)); } return true; }