/// <summary>
 /// Add or replace an element with the provided <paramref name="key"/>, <paramref name="value"/> and <paramref name="size"/> to
 /// <see cref="ICnmCache{TKey,TValue}"/>.
 /// </summary>
 /// <param name="key">
 /// The object used as the key of the element. Can't be <see langword="null"/> reference.
 /// </param>
 /// <param name="value">
 /// The object used as the value of the element to add or replace. <see langword="null"/> is allowed.
 /// </param>
 /// <param name="size">
 /// The element's size. Normally bytes, but can be any suitable unit of measure.
 /// </param>
 /// <returns>
 /// <see langword="true"/>if element has been added successfully to the <see cref="ICnmCache{TKey,TValue}"/>;
 /// otherwise <see langword="false"/>.
 /// </returns>
 /// <exception cref="ArgumentNullException">
 /// <paramref name="key"/>is <see langword="null"/>.
 /// </exception>
 /// <exception cref="ArgumentOutOfRangeException">
 /// The element's <paramref name="size"/> is less than 0.
 /// </exception>
 /// <remarks>
 /// <para>
 /// If element's <paramref name="size"/> is larger than <see cref="ICnmCache{TKey,TValue}.MaxElementSize"/>, then element is
 /// not added to the <see cref="ICnmCache{TKey,TValue}"/>, however - possible older element is
 /// removed from the <see cref="ICnmCache{TKey,TValue}"/>.
 /// </para>
 /// <para>
 /// When adding an new element to <see cref="ICnmCache{TKey,TValue}"/> that is limiting total size of elements,
 /// <see cref="ICnmCache{TKey,TValue}"/>will remove less recently used elements until it can fit an new element.
 /// </para>
 /// <para>
 /// When adding an new element to <see cref="ICnmCache{TKey,TValue}"/> that is limiting element count,
 /// <see cref="ICnmCache{TKey,TValue}"/>will remove less recently used elements until it can fit an new element.
 /// </para>
 /// </remarks>
 /// <seealso cref="ICnmCache{TKey,TValue}.IsSizeLimited"/>
 /// <seealso cref="ICnmCache{TKey,TValue}.IsCountLimited"/>
 /// <seealso cref="ICnmCache{TKey,TValue}.Remove"/>
 /// <seealso cref="ICnmCache{TKey,TValue}.RemoveRange"/>
 /// <seealso cref="ICnmCache{TKey,TValue}.TryGetValue"/>
 /// <seealso cref="ICnmCache{TKey,TValue}.Clear"/>
 /// <seealso cref="ICnmCache{TKey,TValue}.PurgeExpired"/>
 public bool Set(TKey key, TValue value, long size)
 {
     lock (m_syncRoot)
     {
         return(m_cache.Set(key, value, size));
     }
 }
Exemple #2
0
 /// <summary>
 /// Cache asset.
 /// </summary>
 /// <param name="asset">
 /// The asset that is being cached.
 /// </param>
 public void Cache(AssetBase asset)
 {
     if (asset != null)
     {
         long size = asset.Data != null ? asset.Data.Length : 1;
         m_cache.Set(asset.ID, asset, size);
         m_cachedCount++;
     }
 }
        /// <summary>
        ///     Cache asset.
        /// </summary>
        /// <param name="assetID"></param>
        /// <param name="asset">
        ///     The asset that is being cached.
        /// </param>
        public void Cache(string assetID, AssetBase asset)
        {
            if (asset != null)
            {
//                MainConsole.Instance.DebugFormat("[CENOME ASSET CACHE]: Caching asset {0}", asset.IDString);

                long size = asset.Data != null ? asset.Data.Length : 1;
                m_cache.Set(asset.IDString, asset, size);
                m_cachedCount++;
            }
        }
Exemple #4
0
        /// <summary>
        /// Cache asset.
        /// </summary>
        /// <param name="asset">
        /// The asset that is being cached.
        /// </param>
        public void Cache(AssetBase asset)
        {
            if (asset != null)
            {
//                m_log.DebugFormat("[CENOME ASSET CACHE]: Caching asset {0}", asset.ID);

                long size = asset.Data != null ? asset.Data.Length : 1;
                m_cache.Set(asset.ID, asset, size);
                m_cachedCount++;
            }
        }