コード例 #1
0
 public void OnRemovalAsync(K key, Task <V> computableValue, RemovalCause cause)
 {
     if (computableValue != null)
     {
         computableValue.ContinueWith(v => @delegate.OnRemoval(key, v.Result, cause));
     }
 }
コード例 #2
0
        internal V Remap(K key, Func <K, V, V> remappingFunction)
        {
            V            oldValue = default(V);
            RemovalCause cause    = RemovalCause.UNKNOWN;

            V nv = data.AddOrUpdate(key, delegate(K k1)
            {
                V newValue = remappingFunction(k1, default(V));
                return(newValue);
            },
                                    delegate(K k1, V v1)
            {
                V newValue = remappingFunction(k1, v1);

                cause = (newValue == null) ? RemovalCause.EXPLICIT : RemovalCause.REPLACED;

                if (HasRemovalListener && !EqualityComparer <V> .Default.Equals(v1, default(V)) && !EqualityComparer <V> .Default.Equals(newValue, v1))
                {
                    oldValue = v1;
                }

                return(newValue);
            });

            if (!EqualityComparer <V> .Default.Equals(oldValue, default(V)))
            {
                NotifyRemoval(key, oldValue, cause);
            }

            return(nv);
        }
コード例 #3
0
 public RemovalNotification(K key, V value, RemovalCause removalCause)
 {
     Validate.Validate.Hard.IsNotNull(removalCause);
     Key          = key;
     Value        = value;
     RemovalCause = removalCause;
 }
コード例 #4
0
ファイル: LocalCache.cs プロジェクト: wallstop/WallNetCore
        private void InternalNotifyOfRemoval(ref K key, ref V value, RemovalCause cause)
        {
            if (!HasRemovalListener)
            {
                return;
            }

            RemovalNotification <K, V> removalNotification = new RemovalNotification <K, V>(key, value, cause);

            RemovalListener(removalNotification);
        }
コード例 #5
0
 /// <summary>
 /// Asynchronously sneds a removal notification to the listener.
 /// </summary>
 /// <param name="key"></param>
 /// <param name="value"></param>
 /// <param name="cause"></param>
 internal virtual void NotifyRemoval(K key, V value, RemovalCause cause)
 {
     Task.Run(() => RemovalListener.OnRemoval(key, value, cause));
 }
コード例 #6
0
 public void OnRemoval(K key, V value, RemovalCause cause)
 {
     @delegate.OnRemoval(key, value, cause);
 }
コード例 #7
0
ファイル: LocalCache.cs プロジェクト: wallstop/WallNetCore
        private void Removal(K key, Func <bool> alreadyExpired, RemovalCause removalCause)
        {
            if (alreadyExpired())
            {
                /* Someone else already cleaned up after us :( */
                return;
            }

            using (new CriticalRegion(Lock, CriticalRegion.LockType.Write))
            {
                FatTimer existingTimer;
                if (Timers.TryGetValue(key, out existingTimer))
                {
                    existingTimer.Dispose();
                    Timers.Remove(key);
                }
                if (!HasRemovalListener)
                {
                    if (IsCapped)
                    {
                        LruCache.Remove(key);
                    }
                    else
                    {
                        Cache.Remove(key);
                    }
                    return;
                }

                bool removed = false;
                V    removedValue;
                if (IsCapped)
                {
                    Node <K, V> removedValueWrapper;
                    removed = LruCache.TryGetValue(key, out removedValueWrapper);
                    if (removed)
                    {
                        removedValue = removedValueWrapper.Data;
                        removedValueWrapper.Previous.Next = removedValueWrapper.Next;
                        removedValueWrapper.Next.Previous = removedValueWrapper.Previous;
                        LruCache.Remove(key);
                    }
                    else
                    {
                        removedValue = default(V);
                    }
                }
                else
                {
                    removed = Cache.TryGetValue(key, out removedValue);
                    if (removed)
                    {
                        Cache.Remove(key);
                    }
                }

                if (removed)
                {
                    InternalNotifyOfRemoval(ref key, ref removedValue, removalCause);
                }
            }
        }
コード例 #8
0
 public void Delete(K key, V value, RemovalCause cause)
 {
     return;
 }