public VALUE GetOrAdd(KEY key, Func <KEY, VALUE> valueFactory)
        {
            var result = GetOrAddInternal(key, valueFactory);

            if (result != null && !PermaMode)
            {
                TimedReferenceController.KeepAlive(result, KeepAliveType.ACCESS);
            }
            return(result);
        }
Beispiel #2
0
        public static void DigestUpdate(UpdateState state)
        {
            Queue <Callback <UpdateState> > _callbacks;

            lock (_UpdateCallbacks)
            {
                _callbacks = new Queue <Callback <UpdateState> >(_UpdateCallbacks);
                _UpdateCallbacks.Clear();
            }
            while (_callbacks.Count > 0)
            {
                _callbacks.Dequeue()(state);
            }

            List <UpdateHook> _hooks;
            List <UpdateHook> toRemove = new List <UpdateHook>();

            lock (_UpdateHooks)
            {
                _hooks = new List <UpdateHook>(_UpdateHooks);
            }
            for (int i = 0; i < _hooks.Count; i++)
            {
                var item = _hooks[i];
                item.Callback(state);
                if (item.RemoveNext)
                {
                    toRemove.Add(item);
                }
            }
            lock (_UpdateHooks)
            {
                foreach (var rem in toRemove)
                {
                    _UpdateHooks.Remove(rem);
                }
            }

            //finally, check cache controller
            TimedReferenceController.Tick();
        }