Пример #1
0
        private List <CacheProperty> GetPropertys(int size)
        {
            //list
            var list = new List <CacheProperty>(size);

            //property list
            var propertys = new CacheProperty[HASH_POOL_SIZE][];

            for (int i = 0; i < HASH_POOL_SIZE; i++)
            {
                propertys[i] = Program.CacheManagers[i].GetLastProperty(size);
            }

            //
            for (int i = 0; i < size && list.Count < size; i++)
            {
                for (int j = 0; j < HASH_POOL_SIZE && list.Count < size; j++)
                {
                    if (propertys[j].Length > i)
                    {
                        var item = propertys[j][i];
                        if (item.Expires != 0)
                        {
                            list.Add(item);
                        }
                    }
                }
            }

            return(list);
        }
Пример #2
0
        //允许脏读
        public CacheProperty GetProperty(string key)
        {
            var property = new CacheProperty();
            //
            int hashCode = HashHelper.GetHashCode(key);
            int bucket   = hashCode % this.size;

            //
            byte[] data;
            for (int i = this.buckets[bucket] - 1; i >= 0; i = this.nexts[i])
            {
                if (this.hashCodes[i] == hashCode && this.keys[i] == key)
                {
                    data = this.values[i];
                    //find
                    property.Expires = this.expires[i];
                    property.Key     = this.keys[i];
                    property.Size    = data == null ? 0 : data.Length;
                }
            }
            //
            return(property);
        }