Ejemplo n.º 1
0
        /// <summary>清除缓存</summary>
        /// <param name="reason">原因</param>
        public void ClearCache(String reason)
        {
            _cache?.Clear(reason);

            _singleCache?.Clear(reason);

            var n = _Count;

            if (n < 0L)
            {
                return;
            }

            // 只有小于等于1000时才清空_Count,因为大于1000时它要作为HttpCache的见证
            if (n < 1000L)
            {
                _Count = -1L;
            }
#if !__CORE__
            else
            {
                HttpRuntime.Cache.Remove(CacheKey);
            }
#endif
        }
Ejemplo n.º 2
0
        public void TestClear()
        {
            var cache = new EntityCache <Role>
            {
                Expire = 2
            };

            // 尝试访问
            var list = cache.Entities;

            Assert.Equal(1, cache.Times);

            cache.Clear("TestClear", false);

            Thread.Sleep(1000);
            Assert.Equal(1, cache.Times);

            // 再次访问
            var list2 = cache.Entities;

            Assert.Equal(1, cache.Times);
            Thread.Sleep(1000);
            Assert.Equal(2, cache.Times);

            cache.Clear("TestClear", true);

            // 再次访问
            list2 = cache.Entities;

            Assert.Equal(3, cache.Times);

            // 等待更新完成
            Thread.Sleep(1000);
            Assert.Equal(3, cache.Times);
        }
Ejemplo n.º 3
0
        /// <summary>清除缓存</summary>
        /// <param name="reason">原因</param>
        public void ClearCache(String reason)
        {
            _cache?.Clear(reason);

            _singleCache?.Clear(reason);

            //_Count = -1L;
        }
Ejemplo n.º 4
0
        /// <summary>清除缓存</summary>
        /// <param name="reason">原因</param>
        public void ClearCache(String reason)
        {
            _cache?.Clear(reason);

            _singleCache?.Clear(reason);

            // Count提供的是非精确数据,避免频繁更新
            //_Count = -1L;
            //_NextCount = DateTime.MinValue;
        }
Ejemplo n.º 5
0
 public bool TestAddGet()
 {
     try
     {
         bool res;
         m_Cache.Add(m_Dummy);
         m_Cache.Clear();
         res = m_Cache.ForceGet(m_Dummy.Id).Id == m_Dummy.Id;     // get from Repository
         return(res && m_Cache.Get(m_Dummy.Id).Id == m_Dummy.Id); // get form Cache
     }
     catch
     {
         return(false);
     }
 }
Ejemplo n.º 6
0
        private void AreaChanged(AreaInstance area)
        {
            try
            {
                ValidEntitiesByType = NewValidEntitiesByType();
                EntityCache.Clear();

                var dataLocalPlayer = _gameController.Game.IngameState.Data.LocalPlayer;

                if (Player != null && Player.Address == dataLocalPlayer.Address)
                {
                    return;
                }
                if (!dataLocalPlayer.Path.StartsWith("Meta"))
                {
                    return;
                }

                Player         = dataLocalPlayer;
                Player.IsValid = true;
                PlayerUpdate?.Invoke(this, Player);
            }
            catch (Exception e)
            {
                DebugWindow.LogError($"EntityListWrapper.AreaChanged -> {e}");
            }
        }
Ejemplo n.º 7
0
        public void CreateTableDifferentName()
        {
            EntityCache.Clear(); //clear entity cache
            Repository <User> userRepo = new Repository <User>(Fixture.Connection);

            userRepo.DropTable();
            userRepo.CreateTable();
            Assert.True(userRepo.IsTableExists());
        }
Ejemplo n.º 8
0
        public void CreateTableIdentity()
        {
            EntityCache.Clear(); //clear entity cache
            Repository <City> cityRepo = new Repository <City>(Fixture.Connection);

            cityRepo.DropTable();
            cityRepo.CreateTable();
            Assert.True(cityRepo.IsTableExists());
        }
Ejemplo n.º 9
0
        public void CreateTableWithCompositePrimaryKeyVarchar()
        {
            EntityCache.Clear(); //clear entity cache
            Repository <Address> addRepo = new Repository <Address>(Fixture.Connection);

            addRepo.DropTable();
            addRepo.CreateTable();
            Assert.True(addRepo.IsTableExists());
        }
Ejemplo n.º 10
0
        public void CreateTableWithPrimaryKeyVarchar()
        {
            EntityCache.Clear(); //clear entity cache
            Repository <Organization> orgRepo = new Repository <Organization>(Fixture.Connection);

            orgRepo.DropTable();
            orgRepo.CreateTable();
            Assert.True(orgRepo.IsTableExists());
        }
Ejemplo n.º 11
0
        /// <summary>清除缓存,直接执行SQl语句或事务回滚时使用</summary>
        /// <param name="reason">原因</param>
        /// <param name="isUpdateMode">是否执行更新实体操作</param>
        /// <remarks>http://www.newlifex.com/showtopic-1216.aspx</remarks>
        private void ForceClearCache(String reason, Boolean isUpdateMode)
        {
            var clearEntityCache = false;

            if (_cache != null && _cache.Using)
            {
                clearEntityCache = true;
                _cache.Clear(reason);
            }

            // 因为单对象缓存在实际应用场景中可能会非常庞大
            // 添加、删除不再维护单对象缓存,新添加的会自动获取,删除的一直保留在内存中等待SingleCache的定时清理或RemoveFirst方法慢慢清除
            // 如果清理了实体缓存证明当前实体数据量不大,也清除单对象缓存,尽量使单对象缓存的实体对象与实体缓存中的实体对象一致
            if (isUpdateMode || clearEntityCache)
            {
                if (_singleCache != null && _singleCache.Using)
                {
                    Task.Factory.StartNew(() =>
                    {
                        _singleCache.Clear(reason);
                        _singleCache.Initialize();
                    });
                }
            }

            if (!isUpdateMode)
            {
                Int64 n = _Count;
                if (n < 0L)
                {
                    return;
                }

                // 只有小于等于1000时才清空_Count,因为大于1000时它要作为HttpCache的见证
                if (n > 1000L)
                {
                    HttpRuntime.Cache.Remove(CacheKey);
                }
                else
                {
                    _Count = -1L;
                }
            }
        }
Ejemplo n.º 12
0
        public void CreateIndex()
        {
            EntityCache.Clear(); //clear entity cache
            Repository <City> cityRepo = new Repository <City>(Fixture.Connection);

            cityRepo.CreateTable();
            cityRepo.CreateIndex("idx_cityname", "countryid,state,name", false);

            Assert.True(cityRepo.IsIndexExists("idx_cityname"));
        }
Ejemplo n.º 13
0
        public void CreateTableNoIdentity()
        {
            EntityCache.Clear(); //clear entity cache
            Repository <Country> countryRepo = new Repository <Country>(Fixture.Connection);

            //Drop table if exists
            countryRepo.DropTable();
            countryRepo.CreateTable();

            Assert.True(countryRepo.IsTableExists());
        }
Ejemplo n.º 14
0
        public void CreateContactTableNoIdentityWithGUIDPK()
        {
            Vega.Config.CreatedUpdatedByColumnType = System.Data.DbType.Guid;
            EntityCache.Clear(); //clear entity cache
            Repository <Contact> repo = new Repository <Contact>(Fixture.Connection);

            //Drop table if exists
            repo.DropTable();
            repo.CreateTable();
            Vega.Config.CreatedUpdatedByColumnType = System.Data.DbType.Int32;
            Assert.True(repo.IsTableExists());
        }
Ejemplo n.º 15
0
        public void ClearEmptyCache()
        {
            var cache = new EntityCache <TestEntity>();

            var entity = new TestEntity(Guid.NewGuid());

            cache.Add(entity);

            var entity2 = new TestEntity(Guid.NewGuid());

            cache.Add(entity2);

            cache.Clear();

            cache.All().Should().BeEmpty();
        }