Ejemplo n.º 1
0
        public void MemoryCache()
        {
            var categoryManager = new EntitiesManager <Category>(new MemoryCache <IEnumerable <Category> >());

            for (var i = 0; i < 10; i++)
            {
                Console.WriteLine(categoryManager.GetEntities().Count());
                Thread.Sleep(100);
            }
        }
Ejemplo n.º 2
0
        public void CustomersUsingMemoryCache()
        {
            var entityManager = new EntitiesManager <Customer>((new EntitiesMemoryCache <Customer>()));

            for (var i = 0; i < 10; i++)
            {
                Console.WriteLine(entityManager.GetEntities().Count());
                Thread.Sleep(100);
            }
        }
Ejemplo n.º 3
0
        public void CustomersUsingRedisCache()
        {
            var entityManager = new EntitiesManager <Customer>(new EntitiesRedisCache <Customer>("localhost"));

            for (var i = 0; i < 10; i++)
            {
                Console.WriteLine(entityManager.GetEntities().Count());
                Thread.Sleep(100);
            }
        }
Ejemplo n.º 4
0
        public void CustomersMemoryCache()
        {
            var entitiesManager = new EntitiesManager <Customer>(new MemoryCache <IEnumerable <Customer> >(_customersPrefix));

            for (var i = 0; i < 10; i++)
            {
                Console.WriteLine(entitiesManager.GetEntities().Count());
                Thread.Sleep(100);
            }
        }
Ejemplo n.º 5
0
        public void SuppliersRedisCache()
        {
            var entitiesManager = new EntitiesManager <Supplier>(new RedisCache <IEnumerable <Supplier> >("localhost", _suppliersPrefix));

            for (var i = 0; i < 10; i++)
            {
                Console.WriteLine(entitiesManager.GetEntities().Count());
                Thread.Sleep(100);
            }
        }
Ejemplo n.º 6
0
        public void CategoriesRedisCache()
        {
            var entitiesManager = new EntitiesManager <Category>(new RedisCache <IEnumerable <Category> >("localhost", _categoriesPrefix));

            for (var i = 0; i < 10; i++)
            {
                Console.WriteLine(entitiesManager.GetEntities().Count());
                Thread.Sleep(100);
            }
        }
Ejemplo n.º 7
0
        public void MemoryCacheGenericSupplierWithOutInvalidation()
        {
            var entityManager = new EntitiesManager <Supplier>(new EntitiesMemoryCache <Supplier>());

            for (var i = 0; i < 10; i++)
            {
                Console.WriteLine(entityManager.GetEntities().Count());
                Thread.Sleep(1000);
            }
        }
Ejemplo n.º 8
0
        public void RedisCacheGenericOrder()
        {
            var entityManager = new EntitiesManager <Order>(new EntitiesRedisCache <Order>("localhost"));

            for (var i = 0; i < 10; i++)
            {
                Console.WriteLine(entityManager.GetEntities().Count());
                Thread.Sleep(100);
            }
        }
Ejemplo n.º 9
0
        public void ExcpirationTimeTestInvalidation()
        {
            var entitycache   = new Mock <IEntitiesCache <Category> >();
            var entityManager = new EntitiesManager <Category>(entitycache.Object);

            for (var i = 0; i < 10; i++)
            {
                Console.WriteLine(entityManager.GetEntities().Count());
                Thread.Sleep(100);
            }
            entitycache.Verify(
                n => n.Set(It.IsAny <string>(), It.IsAny <IEnumerable <Category> >(), It.IsAny <DateTimeOffset>()), Times.AtLeast(2));
        }
Ejemplo n.º 10
0
        public void MemoryCacheGenericOrderWithTimeInvalidation()
        {
            var entityManager = new EntitiesManager <Order>(new EntitiesMemoryCache <Order>()
            {
                PolicyLevel = PolicyType.ExpirationTime
            });

            for (var i = 0; i < 10; i++)
            {
                Console.WriteLine(entityManager.GetEntities().Count());
                Thread.Sleep(1000);
            }
        }
Ejemplo n.º 11
0
        public void CacheItemPolicy()
        {
            var policy = new CacheItemPolicy();

            policy.ChangeMonitors.Add(new SqlChangeMonitor(new System.Data.SqlClient.SqlDependency(new SqlCommand("Select * from Northwind.Category"))));
            var entitycache   = new Mock <IEntitiesCache <Category> >();
            var entityManager = new EntitiesManager <Category>(entitycache.Object);

            for (var i = 0; i < 10; i++)
            {
                Console.WriteLine(entityManager.GetEntities().Count());
                Thread.Sleep(1000);
            }
            entitycache.Verify(
                n => n.Set(It.IsAny <string>(), It.IsAny <IEnumerable <Category> >(), It.IsAny <DateTimeOffset>()), Times.AtLeast(2));
        }
Ejemplo n.º 12
0
        public void MemoryCacheGenericSupplierWithChangeDbInvalidation()
        {
            var entityManager = new EntitiesManager <Supplier>(new EntitiesMemoryCache <Supplier>
            {
                PolicyLevel = PolicyType.ChangeMonitorSql
            });
            var supplier = new Supplier
            {
                CompanyName = "Company",
                ContactName = "Contact"
            };

            for (var i = 0; i < 10; i++)
            {
                if (i == 5)
                {
                    entityManager.AddItem(supplier);
                }
                Console.WriteLine(entityManager.GetEntities().Count());
            }
        }