public string DebugCacheStatus() { string strStatus = string.Empty; List <string> strKeyList = m_CacheHitRatio.KeyList(); Int32 nSize = strKeyList == null ? 0 : strKeyList.Count; for (Int32 i = 0; i < nSize; ++i) { string strKey = strKeyList[i]; CCacheHitRatio cacheHit = null; CCacheSet cacheSet = null; if (m_CacheHitRatio.QuickFind(strKey, ref cacheHit) == false || cacheHit == null) { continue; } m_Cache.QuickFind(strKey, ref cacheSet); strStatus += string.Format("Cache:{0}, Try Times:{1}, Hit Times:{2}, Hit Ratio:{3:P2}, Cache Count:{4}, Cache Slot:{5}", strKey, cacheHit.MissTime + cacheHit.HitTime, cacheHit.HitTime, cacheHit.HitRation(), cacheSet == null ? 0 : cacheSet.CacheSize(), cacheSet == null ? 0 : cacheSet.SlotSize()); } return(strStatus); }
/// <summary> /// 试图命中缓存 /// </summary> /// <param name="strCacheKey"></param> /// <param name="rOutCacheObject"></param> /// <returns></returns> public bool TryHitCache(string strCacheKey, ref System.Object rOutCacheObject) { rOutCacheObject = null; if (string.IsNullOrEmpty(strCacheKey) == true) { return(false); } #if BTDEBUG CCacheHitRatio cacheHit = null; if (m_CacheHitRatio.QuickFind(strCacheKey, ref cacheHit) == false || cacheHit == null) { cacheHit = new CCacheHitRatio(); m_CacheHitRatio.Add(strCacheKey, cacheHit); } #endif if (m_Cache == null) { #if BTDEBUG cacheHit.MissTime += 1; #endif return(false); } CCacheSet cacheSet = null; if (m_Cache.QuickFind(strCacheKey, ref cacheSet) == false || cacheSet == null) { #if BTDEBUG cacheHit.MissTime += 1; #endif return(false); } rOutCacheObject = cacheSet.PopCache(); if (rOutCacheObject == null) { #if BTDEBUG cacheHit.MissTime += 1; #endif return(false); } #if BTDEBUG cacheHit.HitTime += 1; #endif return(true); }