static FastReflectionCaches()
 {
     MethodInvokerCache      = new ActionCache <MethodInfo, MethodInvoker>(mi => new MethodInvoker(mi));
     PropertyAccessorCache   = new ActionCache <PropertyInfo, PropertyAccessor>(pi => new PropertyAccessor(pi));
     FieldAccessorCache      = new ActionCache <FieldInfo, FieldAccessor>(fi => new FieldAccessor(fi));
     ConstructorInvokerCache = new ActionCache <ConstructorInfo, ConstructorInvoker>(ci => new ConstructorInvoker(ci));
 }
Example #2
0
 public CommandFactory(ISidiBarraniServerApi sidiBarraniServerApi, GameInfo gameInfo, PlayerInfo playerInfo, ActionCache actionCache)
 {
     ServerApi   = sidiBarraniServerApi;
     GameInfo    = gameInfo;
     PlayerInfo  = playerInfo;
     ActionCache = actionCache;
 }
        public SidiBarraniServerImplementation()
        {
            var rules = new Rules();

            _actionCache = new ActionCache(rules);
            _random      = new Random();
        }
Example #4
0
        public void ContainsCachedItem_1()
        {
            var called = false;
            var cache  = new ActionCache <int, string>(
                (x) => {
                if (x != 1)
                {
                    throw new Exception("test only allows key with value 1");
                }
                if (called)
                {
                    throw new Exception("item 1 has been requested more than once");
                }
                called = true;
                return("value");
            },
                reapStrategy: CacheReapPolicy.LeastUsed,
                expirationStrategy: ExpirationPolicy.SinceFetchedTime,
                expirationDuration: TimeSpan.FromMilliseconds(100)
                );

            Assert.IsFalse(cache.ContainsCachedItem(1));
            var val = cache[1];

            Assert.IsTrue(cache.ContainsCachedItem(1));
            Thread.Sleep(111);
            Assert.IsFalse(cache.ContainsCachedItem(1));
        }
Example #5
0
        public static void SetValue(PropertyInfo property, object instance, object value)
        {
            var key = GetMethodCacheKey(property);

            if (ActionCache.TryGetValue(key, out Action <object, object> a) == false)
            {
                a = MakeSetMethod(property.GetSetMethod(), property.PropertyType);
                ActionCache[key] = a;
            }

            a(instance, value);
        }
Example #6
0
        public static void SetValue(PropertyInfo property, object instance, object value)
        {
            var key = GetMethodCacheKey(property);

            Action <object, object> a;

            if (!ActionCache.TryGetValue(key, out a))
            {
                a = BuildSetAccessor(property.GetSetMethod());
                ActionCache[key] = a;
            }

            a?.Invoke(instance, value);
        }
Example #7
0
        private void loadObservedPage(ActionCache actionCache, List <IPageCache> observedPages)
        {
            List <IPageCache> relatedPages = ControllerMeta.GetRelatedPageCache(actionCache.GetType());

            if (relatedPages == null)
            {
                return;
            }

            foreach (IPageCache pc in relatedPages)
            {
                if (observedPages.Contains(pc) == false)
                {
                    observedPages.Add(pc);
                }
            }
        }
Example #8
0
        public void ExpirationTest_Simple_1()
        {
            var val   = "first";
            var cache = new ActionCache <int, string>(
                (x) => val,
                reapStrategy: CacheReapPolicy.LeastUsed,
                expirationStrategy: ExpirationPolicy.SinceFetchedTime,
                expirationDuration: TimeSpan.FromMilliseconds(100)
                );

            Assert.AreEqual("first", cache[1]);
            val = "second";
            Assert.AreEqual("first", cache[1]);
            Assert.AreEqual("first", cache[1]);
            Thread.Sleep(111);
            Assert.AreEqual("second", cache[1]);
            Assert.AreEqual("second", cache[1]);
            Assert.AreEqual("second", cache[1]);
        }
Example #9
0
        public void SizeTest_Simple_1()
        {
            var cache = new ActionCache <int, string>(
                (x) => x.ToString(),
                reapStrategy: CacheReapPolicy.LeastUsed,
                expirationStrategy: ExpirationPolicy.SinceFetchedTime,
                expirationDuration: TimeSpan.FromMilliseconds(100),
                sizeEstimator: uint.Parse,
                maxCapacity: 100
                );

            Assert.Throws <SoftwareException>(() => { var x = cache[101]; });
            Assert.AreEqual("98", cache[98]);
            Assert.AreEqual(1, cache.GetCachedItems().Count);
            Assert.AreEqual("2", cache[2]);
            Assert.AreEqual(2, cache.GetCachedItems().Count);
            Assert.AreEqual("1", cache[1]);
            Assert.AreEqual(2, cache.GetCachedItems().Count);  // should have purged first item
            Assert.AreEqual(new [] { "1", "2" }, cache.GetAllCachedValues().ToArray());
            Assert.AreEqual("100", cache[100]);
            Assert.AreEqual(1, cache.GetCachedItems().Count);  // should have purged everything
        }
Example #10
0
        private void loadObservedPage( ActionCache actionCache, List<IPageCache> observedPages ) {

            List<IPageCache> relatedPages = ControllerMeta.GetRelatedPageCache( actionCache.GetType() );
            if (relatedPages == null) return;

            foreach (IPageCache pc in relatedPages) {
                if (observedPages.Contains( pc ) == false) observedPages.Add( pc );
            }

        }
Example #11
0
 public Unparser(Grammar grammar, int?seed = null, ActionCache cache = null)
 {
     _grammar  = grammar;
     _saveData = cache ?? new ActionCache();
     Seed(seed);
 }
        private void OnPropertyChanged(string propertyName, ActionCache acao)
        {
            var handler = CacheChanged;

            handler?.Invoke(this, new CacheChangedEventArgs(propertyName, acao));
        }
Example #13
0
 public CacheChangedEventArgs(string chave, ActionCache acao)
 {
     Chave  = chave;
     Status = acao;
 }