예제 #1
0
        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);
                    }
                }
            }
        }
예제 #2
0
        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());
            }
        }
예제 #3
0
        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);
        }
예제 #4
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);
                                }
                            }
                        }
                    }
                }
            }
        }