Beispiel #1
0
        public void RemoveFlagForUser(string flagKey, User user)
        {
            JToken oldValue = null;

            readWriteLock.EnterWriteLock();
            try
            {
                var flagsForUser = inMemoryCache.RetrieveFlags(user);
                if (flagsForUser.TryGetValue(flagKey, out var flag))
                {
                    oldValue = flag.value;
                    flagsForUser.Remove(flagKey);
                    deviceCache.CacheFlagsForUser(flagsForUser, user);
                    inMemoryCache.CacheFlagsForUser(flagsForUser, user);
                }
            }
            finally
            {
                readWriteLock.ExitWriteLock();
            }
            if (oldValue != null)
            {
                flagChangedEventManager.FlagWasDeleted(flagKey, oldValue);
            }
        }
        public void RemoveFlagForUser(string flagKey, User user)
        {
            LdValue oldValue = LdValue.Null;
            bool    existed  = false;

            readWriteLock.EnterWriteLock();
            try
            {
                var flagsForUser = inMemoryCache.RetrieveFlags(user);
                if (flagsForUser.TryGetValue(flagKey, out var flag))
                {
                    existed  = true;
                    oldValue = flag.value;
                    var updatedFlags = flagsForUser.Remove(flagKey); // IImmutableDictionary.Remove() returns a new dictionary
                    deviceCache.CacheFlagsForUser(updatedFlags, user);
                    inMemoryCache.CacheFlagsForUser(updatedFlags, user);
                }
            }
            finally
            {
                readWriteLock.ExitWriteLock();
            }
            if (existed)
            {
                flagChangedEventManager.FlagWasDeleted(flagKey, oldValue);
            }
        }