public bool Check(string id) { AssetBase asset; // XXX:This is probably not an efficient implementation. return(m_cache.TryGetValue(id, out asset)); }
public AssetBase Get(string id, out bool found) { m_getCount++; found = false; AssetBase assetBase; if (m_cache.TryGetValue(id, out assetBase)) { found = true; m_hitCount++; } if (m_getCount == m_debugEpoch) { MainConsole.Instance.DebugFormat( "[ASSET CACHE]: Cached = {0}, Get = {1}, Hits = {2}%, Size = {3} bytes, Avg. A. Size = {4} bytes", m_cachedCount, m_getCount, ((double)m_hitCount / m_getCount) * 100.0, m_cache.Size, m_cache.Size / m_cache.Count); m_getCount = 0; m_hitCount = 0; m_cachedCount = 0; } // if (null == assetBase) // MainConsole.Instance.DebugFormat("[CENOME ASSET CACHE]: Asset {0} not in cache", id); return(assetBase); }
/// <summary> /// Gets the <paramref name="value"/> associated with the specified <paramref name="key"/>. /// </summary> /// <returns> /// <see langword="true"/>if the <see cref="ICnmCache{TKey,TValue}"/> contains an element with /// the specified key; otherwise, <see langword="false"/>. /// </returns> /// <param name="key"> /// The key whose <paramref name="value"/> to get. /// </param> /// <param name="value"> /// When this method returns, the value associated with the specified <paramref name="key"/>, /// if the <paramref name="key"/> is found; otherwise, the /// default value for the type of the <paramref name="value"/> parameter. This parameter is passed uninitialized. /// </param> /// <exception cref="ArgumentNullException"> /// <paramref name="key"/>is <see langword="null"/>. /// </exception> /// <seealso cref="ICnmCache{TKey,TValue}.Set"/> /// <seealso cref="ICnmCache{TKey,TValue}.Remove"/> /// <seealso cref="ICnmCache{TKey,TValue}.RemoveRange"/> /// <seealso cref="ICnmCache{TKey,TValue}.Clear"/> /// <seealso cref="ICnmCache{TKey,TValue}.PurgeExpired"/> public bool TryGetValue(TKey key, out TValue value) { lock (m_syncRoot) { return(m_cache.TryGetValue(key, out value)); } }
/// <summary> /// Get asset stored /// </summary> /// <param name="id"> /// The asset's id. /// </param> /// <returns> /// Asset if it is found from cache; otherwise <see langword="null"/>. /// </returns> /// <remarks> /// <para> /// Caller should always check that is return value <see langword="null"/>. /// Cache doesn't guarantee in any situation that asset is stored to it. /// </para> /// </remarks> public AssetBase Get(string id) { m_getCount++; AssetBase assetBase; if (m_cache.TryGetValue(id, out assetBase)) { m_hitCount++; } if (m_getCount == m_debugEpoch) { Log.InfoFormat( "[ASSET CACHE]: Cached = {0}, Get = {1}, Hits = {2}%, Size = {3} bytes, Avg. A. Size = {4} bytes", m_cachedCount, m_getCount, ((double)m_hitCount / m_getCount) * 100.0, m_cache.Size, m_cache.Size / m_cache.Count); m_getCount = 0; m_hitCount = 0; m_cachedCount = 0; } return(assetBase); }