Exemple #1
0
    /// <summary>
    /// 缓存对象
    /// </summary>
    /// <param name="key">类型</param>
    /// <returns>缓存对象</returns>
    public Tvalue this[Tkey key]
    {
        get
        {
            if (pool.ContainsKey(key))
            {
                Tvalue t = pool[key].Get();
                t.DestroyedEvent += AliveDestroyed;
                aliveList.Add(t);
                return(t);
            }
            return(default(Tvalue));
        }
        set
        {
            if (aliveList.Contains(value))
            {
                aliveList.Remove(value);
            }
            if (value == null)
            {
                return;
            }

            if (pool.ContainsKey(key))
            {
                value.DestroyedEvent -= AliveDestroyed;
                pool[key].Set(value);
            }
            else
            {
                SinglePool <Tvalue> p = new SinglePool <Tvalue>();
                p.SetTempleAndCount(value, cacheCountDic.ContainsKey(key) ? cacheCountDic[key] : 1);
                pool.Add(key, p);
            }
        }
    }