Exemple #1
0
        public Object get(String key)
        {
            int hashKey = (_cacheKeyHead + "$" + key).GetHashCode();

            LocalCacheRecord val = null;

            if (mcc.ContainsKey(hashKey))
            {
                val = mcc[hashKey];
            }

            if (val == null)
            {
                return(null);
            }

            if (val.time < new DateTime().Ticks)
            {
                mcc.Remove(hashKey);
                mks.Remove(hashKey);
                _count--;
                return(null);
            }
            else
            {
                return(val.data);
            }
        }
Exemple #2
0
        public void store(String key, Object obj, int seconds)
        {
            int hashKey          = (_cacheKeyHead + "$" + key).GetHashCode();
            LocalCacheRecord val = new LocalCacheRecord(hashKey, obj, seconds);

            mcc.Add(hashKey, val);
            mks.Add(hashKey);

            _count++;
            if (_count > _max) //总量控制
            {
                int k = mks[0];
                mcc.Remove(k);
                mks.Remove(0);
                _count--;
            }
        }