コード例 #1
0
        public void CacheFlagsFromService(IDictionary <string, FeatureFlag> flags, User user)
        {
            readWriteLock.EnterWriteLock();
            try
            {
                var previousFlags = inMemoryCache.RetrieveFlags(user);
                deviceCache.CacheFlagsForUser(flags, user);
                inMemoryCache.CacheFlagsForUser(flags, user);

                foreach (var flag in flags)
                {
                    bool flagAlreadyExisted = previousFlags.ContainsKey(flag.Key);
                    bool flagValueChanged   = false;
                    if (flagAlreadyExisted)
                    {
                        var originalFlag = previousFlags[flag.Key];
                        flagValueChanged = originalFlag.value != flag.Value.value;
                    }

                    // only update the Listeners if the flag value changed
                    if (flagValueChanged)
                    {
                        flagListenerUpdater.FlagWasUpdated(flag.Key, flag.Value.value);
                    }
                }
            }
            finally
            {
                readWriteLock.ExitWriteLock();
            }
        }
コード例 #2
0
        public void CanCacheFlagsInMemory()
        {
            var jsonFlags = @"{""flag1"":{""value"":1},""flag2"":{""value"":2}}";
            var flags     = TestUtil.DecodeFlagsJson(jsonFlags);

            inMemoryCache.CacheFlagsForUser(flags, user1);
            var flagsRetrieved = inMemoryCache.RetrieveFlags(user1);

            Assert.Equal(2, flagsRetrieved.Count);
            Assert.Equal(flags["flag1"], flagsRetrieved["flag1"]);
            Assert.Equal(flags["flag2"], flagsRetrieved["flag2"]);
        }
コード例 #3
0
        public FlagCacheManager(IUserFlagCache inMemoryCache,
                                IUserFlagCache deviceCache,
                                IFlagListenerUpdater flagListenerUpdater,
                                User user)
        {
            this.inMemoryCache       = inMemoryCache;
            this.deviceCache         = deviceCache;
            this.flagListenerUpdater = flagListenerUpdater;

            var flagsFromDevice = deviceCache.RetrieveFlags(user);

            inMemoryCache.CacheFlagsForUser(flagsFromDevice, user);
        }
コード例 #4
0
        public void CacheFlagsFromService(IDictionary <string, FeatureFlag> flags, User user)
        {
            List <Tuple <string, JToken, JToken> > changes = null;

            readWriteLock.EnterWriteLock();
            try
            {
                var previousFlags = inMemoryCache.RetrieveFlags(user);
                deviceCache.CacheFlagsForUser(flags, user);
                inMemoryCache.CacheFlagsForUser(flags, user);

                foreach (var flag in flags)
                {
                    if (previousFlags.TryGetValue(flag.Key, out var originalFlag))
                    {
                        if (!JToken.DeepEquals(originalFlag.value, flag.Value.value))
                        {
                            if (changes == null)
                            {
                                changes = new List <Tuple <string, JToken, JToken> >();
                            }
                            changes.Add(Tuple.Create(flag.Key, flag.Value.value, originalFlag.value));
                        }
                    }
                }
            }
            finally
            {
                readWriteLock.ExitWriteLock();
            }
            if (changes != null)
            {
                foreach (var c in changes)
                {
                    flagChangedEventManager.FlagWasUpdated(c.Item1, c.Item2, c.Item3);
                }
            }
        }
コード例 #5
0
        public void CanCacheFlagsInMemory()
        {
            var text  = JSONReader.FeatureFlagJSON();
            var flags = JsonConvert.DeserializeObject <IDictionary <string, FeatureFlag> >(text);

            inMemoryCache.CacheFlagsForUser(flags, user1);
            var flagsRetrieved = inMemoryCache.RetrieveFlags(user1);

            Assert.Equal(flags.Count, flagsRetrieved.Count);
            var secondFlag          = flags.Values.ToList()[1];
            var secondFlagRetrieved = flagsRetrieved.Values.ToList()[1];

            Assert.Equal(secondFlag, secondFlagRetrieved);
        }
コード例 #6
0
        public FlagCacheManager(IUserFlagCache inMemoryCache,
                                IUserFlagCache deviceCache,
                                IFlagChangedEventManager flagChangedEventManager,
                                User user)
        {
            this.inMemoryCache           = inMemoryCache;
            this.deviceCache             = deviceCache;
            this.flagChangedEventManager = flagChangedEventManager;

            var flagsFromDevice = deviceCache.RetrieveFlags(user);

            if (flagsFromDevice != null)
            {
                inMemoryCache.CacheFlagsForUser(flagsFromDevice, user);
            }
        }
コード例 #7
0
 public void CacheFlagsFromService(IImmutableDictionary <string, FeatureFlag> flags, User user)
 {
     _flagCache.CacheFlagsForUser(flags, user);
 }