Beispiel #1
0
        /// <summary>
        /// 监测
        /// </summary>
        /// <param name="caches"></param>
        /// <param name="timeLen"></param>
        /// <returns></returns>
        private void ProcessValidate(CacheEntity[] caches, int timeLen, Dictionary <int, int> index, ReaderWriterLockSlim lockSlim)
        {
            //如果是大数据量,要考虑设置Parallel线程
            DateTime cur = DateTime.Now;

            lockSlim.EnterWriteLock();
            try
            {
                Parallel.For(0, PageCacheNum, (i, loopState) =>
                {
                    CacheEntity entity = caches[i];
                    if (entity == null)
                    {
                        loopState.Break();
                        return;
                    }
                    else
                    {
                        if ((cur - entity.DateTime).TotalMinutes > timeLen)
                        {
                            index.Remove(entity.PageNum);
                            caches[i] = null;
                        }
                    }
                });
            }
            finally
            {
                lockSlim.ExitWriteLock();
            }
        }
Beispiel #2
0
        /// <summary>
        /// 添加分页缓存
        /// </summary>
        /// <param name="pageNum">页号</param>
        /// <param name="data">数据</param>
        public DataTable Add(int pageNum, DataTable data)
        {
            lockDt.EnterWriteLock();
            DataTable table = null;

            try
            {
                int curIndex = Interlocked.Increment(ref dtIndex) % PageCacheNum;
                if (m_tables[curIndex] != null)
                {
                    dicDtIndex.Remove(m_tables[curIndex].PageNum);
                    table = m_tables[curIndex].DataTable;
                }
                m_tables[curIndex]  = new CacheEntity(data, pageNum);
                dicDtIndex[pageNum] = curIndex;
            }
            finally
            {
                lockDt.ExitWriteLock();
            }
            return(table);
        }
Beispiel #3
0
        /// <summary>
        /// 分页数据缓存
        /// </summary>
        /// <param name="pageNum">分页页号</param>
        /// <param name="model">Model数据</param>
        public List <object> Add(int pageNum, List <object> model)
        {
            lockmodel.EnterWriteLock();
            List <object> list = null;

            try
            {
                int curIndex = Interlocked.Increment(ref modelIndex) % PageCacheNum;
                if (m_models[curIndex] != null)
                {
                    dicModelIndex.Remove(m_models[curIndex].PageNum);
                    list = m_models[curIndex].Model;
                }
                m_models[curIndex]     = new CacheEntity(model, pageNum);
                dicModelIndex[pageNum] = curIndex;
            }
            finally
            {
                lockmodel.ExitWriteLock();
            }

            return(list);
        }