private void TryFixPool()
        {
            int freeCacheCount = GetFreeCacheCount();
            int cacheCount     = GetCacheCount();

            if ((((float)cacheCount) / ((float)mCacheBlockMaxCount)) >= 0.9f)
            {
                if ((((float)freeCacheCount) / ((float)cacheCount)) < 0.2f)
                {
                    mCacheBlockMaxCount += 0x20;
                    if (mCacheBlockMaxCount > mBlockLimitCount)
                    {
                        mCacheBlockMaxCount = mBlockLimitCount;
                    }
                }
                else
                {
                    for (int i = 0; i < pool.Count; i++)
                    {
                        CachedObjectInfo info = pool[i];
                        int num4 = info.GetFreeCacheCount();
                        info.Shrink(num4 / 2);
                    }
                }
            }
        }
        private void try_fix_pool()
        {
            int free_cache_count = get_free_cache_count();
            int cache_count      = get_cache_count();

            if ((((float)cache_count) / ((float)cache_block_max_count_)) >= 0.9f)
            {
                if ((((float)free_cache_count) / ((float)cache_count)) < 0.2f)
                {
                    cache_block_max_count_ += 32;
                    if (cache_block_max_count_ > block_limit_count_)
                    {
                        cache_block_max_count_ = block_limit_count_;
                    }
                }
                else
                {
                    for (int i = 0; i < pool_.Count; i++)
                    {
                        CachedObjectInfo info = pool_[i];
                        int num = info.get_free_cache_count();
                        info.shrink(num / 2);
                    }
                }
            }
        }
        public bool add_cache(object _key, object _value)
        {
            if ((_key == null) || (_value == null))
            {
                return(false);
            }
            CachedObjectInfo cache_info = get_cache_info(_key);

            if (cache_info == null)
            {
                cache_info = add_cache_info(_key);
                if (cache_info == null)
                {
                    return(false);
                }
            }
            if (cache_info.cached_obj(_value.GetHashCode()))
            {
                cache_info.add_to_cache(_value);
                return(true);
            }
            if (get_cache_count() >= cache_block_max_count_)
            {
                try_fix_pool();
            }
            if (get_cache_count() > cache_block_max_count_)
            {
                return(false);
            }
            cache_info.add_to_cache(_value);
            return(true);
        }
        public bool AddCache(object key, object value)
        {
            if ((key == null) || (value == null))
            {
                return(false);
            }
            CachedObjectInfo cacheInfo = GetCacheInfo(key);

            if (cacheInfo == null)
            {
                cacheInfo = AddCacheInfo(key);
                if (cacheInfo == null)
                {
                    return(false);
                }
            }
            if (cacheInfo.CachedObj(value.GetHashCode()))
            {
                cacheInfo.AddToCache(value);
                return(true);
            }
            if (GetCacheCount() >= mCacheBlockMaxCount)
            {
                TryFixPool();
            }
            if (GetCacheCount() > mCacheBlockMaxCount)
            {
                return(false);
            }
            cacheInfo.AddToCache(value);
            return(true);
        }
Exemple #5
0
    private void pushCacheObject(string key, Object obj)
    {
        if (obj == null)
        {
            return;
        }

        if (isPreloadingCachedMode)
        {
            preload_cached_set[key] = obj;
            return;
        }

        if (cached_objects.ContainsKey(key))
        {
            cached_objects[key].cacheTime = Time.realtimeSinceStartup;
            cached_objects[key].cacheObj  = obj;
        }
        else
        {
            CachedObjectInfo coi = new CachedObjectInfo();
            coi.cacheObj  = obj;
            coi.cacheTime = Time.realtimeSinceStartup;
            cached_objects.Add(key, coi);
        }
    }
        public void ClearCache(object key)
        {
            CachedObjectInfo cacheInfo = GetCacheInfo(key);

            if (cacheInfo != null)
            {
                cacheInfo.Shrink(cacheInfo.GetFreeCacheCount());
            }
        }
        public void clear_cache(object _key)
        {
            CachedObjectInfo cache_info = get_cache_info(_key);

            if (cache_info != null)
            {
                cache_info.shrink(cache_info.get_free_cache_count());
            }
        }
        public int shrink_cache(object _key, int _max_shrink_count)
        {
            CachedObjectInfo cache_info = get_cache_info(_key);

            if ((cache_info != null) && (_max_shrink_count > 0))
            {
                return(cache_info.shrink(_max_shrink_count));
            }
            return(0);
        }
        public int ShrinkCache(object key, int maxShrinkCount)
        {
            CachedObjectInfo cacheInfo = GetCacheInfo(key);

            if ((cacheInfo != null) && (maxShrinkCount > 0))
            {
                return(cacheInfo.Shrink(maxShrinkCount));
            }
            return(0);
        }
        public int GetFreeCacheCount(object key)
        {
            CachedObjectInfo cacheInfo = GetCacheInfo(key);

            if (cacheInfo == null)
            {
                return(0);
            }
            return(cacheInfo.GetFreeCacheCount());
        }
Exemple #11
0
        public int get_free_cache_count(object _key)
        {
            CachedObjectInfo cache_info = get_cache_info(_key);

            if (cache_info == null)
            {
                return(0);
            }
            return(cache_info.get_free_cache_count());
        }
Exemple #12
0
        public void remove_from_cache(string _key, object _value)
        {
            if ((_key == null) || (_value == null))
            {
                return;
            }
            CachedObjectInfo cache_info = get_cache_info(_key);

            if (cache_info == null)
            {
                return;
            }
            cache_info.remove_from_cache(_value.GetHashCode());
        }
        private CachedObjectInfo AddCacheInfo(object key)
        {
            if (key == null)
            {
                return(null);
            }
            if (IsContainCacheInfo(key))
            {
                return(GetCacheInfo(key));
            }
            CachedObjectInfo item = new CachedObjectInfo();

            item.InitCache(key, mReleaser);
            pool.Add(item);
            return(item);
        }
Exemple #14
0
        private CachedObjectInfo add_cache_info(object _key)
        {
            if (_key == null)
            {
                return(null);
            }
            if (is_contain_cache_info(_key))
            {
                return(get_cache_info(_key));
            }
            CachedObjectInfo item = new CachedObjectInfo();

            item.init_cache(_key, releaser_);
            pool_.Add(item);
            return(item);
        }
        public object TryHitCache(object key)
        {
            if (key == null)
            {
                return(null);
            }
            CachedObjectInfo cacheInfo = GetCacheInfo(key);

            if (cacheInfo == null)
            {
                return(null);
            }
            object obj2 = cacheInfo.TryHitCache();

            if (obj2 != null)
            {
                cacheInfo.UpdateWeight(Time.realtimeSinceStartup);
            }
            return(obj2);
        }
Exemple #16
0
        public object try_hit_cache(object _key)
        {
            if (_key == null)
            {
                return(null);
            }
            CachedObjectInfo cache_info = get_cache_info(_key);

            if (cache_info == null)
            {
                return(null);
            }
            object obj = cache_info.try_hit_cache();

            if (obj != null)
            {
                cache_info.update_weight(Time.time);
            }
            return(obj);
        }
        public void Update()
        {
            float realtimeSinceStartup = Time.realtimeSinceStartup;

            if ((realtimeSinceStartup - mLastUpdateTime) >= 5f)
            {
                mLastUpdateTime = realtimeSinceStartup;
                if (pool != null)
                {
                    int index = UnityEngine.Random.Range(0, pool.Count - 1);
                    if ((index >= 0) && (index < pool.Count))
                    {
                        CachedObjectInfo info = pool[index];
                        if (info == null)
                        {
                            pool.RemoveAt(index);
                        }
                        else
                        {
                            float num3           = Time.realtimeSinceStartup - info.GetWeight();
                            int   maxShrinkCount = (int)(num3 / 60f);
                            if (maxShrinkCount > 0)
                            {
                                int freeCacheCount = info.GetFreeCacheCount();
                                if (freeCacheCount <= 0)
                                {
                                    pool.RemoveAt(index);
                                }
                                else
                                {
                                    maxShrinkCount = (maxShrinkCount <= freeCacheCount) ? maxShrinkCount : freeCacheCount;
                                    info.Shrink(maxShrinkCount);
                                }
                            }
                        }
                    }
                }
            }
        }
Exemple #18
0
        public void update()
        {
            float time = Time.time;

            if ((time - last_update_time_) >= update_frequency_)
            {
                last_update_time_ = time;
                if (pool_ != null)
                {
                    int index = UnityEngine.Random.Range(0, pool_.Count);
                    if ((index >= 0) && (index < pool_.Count))
                    {
                        CachedObjectInfo info = pool_[index];
                        if (info == null)
                        {
                            pool_.RemoveAt(index);
                        }
                        else
                        {
                            float num = Time.time - info.get_weight();
                            int   max_shrink_count = (int)(num / worn_time_);
                            if (max_shrink_count > 0)
                            {
                                int free_cache_count = info.get_free_cache_count();
                                if (free_cache_count <= 0)
                                {
                                    pool_.RemoveAt(index);
                                }
                                else
                                {
                                    max_shrink_count = (max_shrink_count <= free_cache_count) ? max_shrink_count : free_cache_count;
                                    info.shrink(max_shrink_count);
                                }
                            }
                        }
                    }
                }
            }
        }