Ejemplo n.º 1
0
        public bool Touch(ITtReference <TValue> @ref)
        {
            bool touched = _lruTt.Touch(@ref) || _depthTt.Touch(@ref);

            Debug.Assert(touched);
            return(touched);
        }
Ejemplo n.º 2
0
        public bool Update(ITtReference <TValue> @ref, TValue newValue)
        {
            if (!(@ref is LruNode <TValue> node) || node.HasExpired)
            {
                throw new ArgumentException("", nameof(@ref));
            }

            if (Touch(node))
            {
                node.Value = newValue;
                return(true);
            }
            return(false);
        }
Ejemplo n.º 3
0
        public bool Touch(ITtReference <TValue> @ref)
        {
            if (!(@ref is LruNode <TValue> node) || node.HasExpired)
            {
                throw new ArgumentException("", nameof(@ref));
            }

            if (_dict.TryGetValue(node.Key, out var dictNode) && ReferenceEquals(node, dictNode))
            {
                Log.Debug("(lru) Node {0} was hit, moving to top of cache", node);
                node.Remove();
                _nodes.AddToTop(node);
                return(true);
            }

            return(false); // node isn't from here or got evicted
        }
Ejemplo n.º 4
0
        public bool Update(ITtReference <TValue> @ref, TValue newValue)
        {
            if (!(@ref is LruNode <TValue> node) || node.HasExpired)
            {
                throw new ArgumentException("", nameof(@ref));
            }

            if (Touch(node))
            {
                var(oldDepth, newDepth) = (node.Value.Depth, newValue.Depth);
                Debug.Assert(newDepth >= oldDepth); // so we don't have to worry about updating _minDepth
                node.Value = newValue;

                // we also have to move the node to the appropriate list if its depth has changed
                if (newDepth > oldDepth)
                {
                    node.Remove();
                    EnsureDepth(newDepth);
                    _lists[newDepth].AddToTop(node);
                }
                return(true);
            }
            return(false);
        }
Ejemplo n.º 5
0
 public bool Update(ITtReference <TValue> @ref, TValue newValue)
 {
     return(_lruTt.Update(@ref, newValue) || _depthTt.Update(@ref, newValue));
 }