Пример #1
0
        /// <summary>
        /// 读取数据对象
        /// </summary>
        /// <param name="bean"></param>
        /// <returns></returns>
        public T GetCache(T bean, params string[] args)
        {
            if (bean == null)
            {
                throw new Exception("bean 不能为 NULL");
            }
            T      row = null;
            string ck  = "t_" + CombineCacheKey(bean);

            if (CondRowCache.Get(ck, ref row))
            {
                return(_Get(row, args));
            }

            if (!_lock.Add(ck))
            {
                System.Threading.Thread.Sleep(5);
                if (CondRowCache.Get(ck, ref row))
                {
                    return(_Get(row, args));
                }
            }
            try
            {
                row = Get(bean);
                if (row == null)
                {
                    CondRowCache.Add(ck, null, 5);
                }
                else
                {
                    CondRowCache.Add(ck, row);
                }
            }
            finally
            {
                _lock.Remove(ck);
            }
            return(_Get(row, args));
        }
Пример #2
0
        /// <summary>
        /// 按指定条件对象缓存中的数据对象
        /// </summary>
        /// <param name="cond"></param>
        /// <returns></returns>
        public T GetCache(Sql cond)
        {
            if (cond == null)
            {
                throw new Exception("cond 不能为 NULL");
            }
            T      row = null;
            string ck  = "cond_" + CombineCacheKey(cond);

            if (CondRowCache.Get(ck, ref row))
            {
                return(_Clone(row));
            }

            if (!_lock.Add(ck))
            {
                System.Threading.Thread.Sleep(5);
                if (CondRowCache.Get(ck, ref row))
                {
                    return(_Clone(row));
                }
            }
            try
            {
                row = Get(cond);
                if (row == null)
                {
                    CondRowCache.Add(ck, null, 5);
                }
                else
                {
                    CondRowCache.Add(ck, row);
                }
            }
            finally
            {
                _lock.Remove(ck);
            }
            return(_Clone(row));
        }
Пример #3
0
        /// <summary>
        /// 读取缓存中的数据对象
        /// </summary>
        /// <typeparam name="V"></typeparam>
        /// <param name="col"></param>
        /// <param name="val"></param>
        /// <param name="args"></param>
        /// <returns></returns>
        public T GetCache <V>(string col, V val, params string[] args)
        {
            T      row = null;
            string ck  = "col_" + CombineCacheKey(col, val);

            if (CondRowCache.Get(ck, ref row))
            {
                return(_Get(row, args));
            }

            if (!_lock.Add(ck))
            {
                System.Threading.Thread.Sleep(5);
                if (CondRowCache.Get(ck, ref row))
                {
                    return(_Get(row, args));
                }
            }
            try
            {
                row = Get(col, val);
                if (row == null)
                {
                    CondRowCache.Add(ck, null, 5);
                }
                else
                {
                    CondRowCache.Add(ck, row);
                }
            }
            finally
            {
                _lock.Remove(ck);
            }
            return(_Get(row, args));
        }