Beispiel #1
0
        public void Add(CacheItem <K, V> cacheItem)
        {
            var startIndex = (_hashAlgorithm.Hash(cacheItem.Key) % _sets) * _entries;
            var added      = false;

            for (var slot = startIndex; slot < startIndex + _entries; slot++)
            {
                if (_cache[slot] == null)
                {
                    _cache[slot] = cacheItem;
                    added        = true;
                    break;
                }
            }

            if (!added)
            {
                var slot = _evictionPolicy.Evict(_cache, startIndex, _entries);
                _cache[slot] = cacheItem;
            }
        }