Ejemplo n.º 1
0
        public static List <BaseAreaEntity> GetListByParentByCache(string parentId, bool fefreshCache = false)
        {
            List <BaseAreaEntity> result = null;

            string key = "AreaList:";

            if (!string.IsNullOrEmpty(parentId))
            {
                key = key + parentId;
            }

            if (!fefreshCache)
            {
                result = GetListCache(key);
            }

            if (result == null)
            {
                BaseAreaManager manager = new DotNet.Business.BaseAreaManager();
                result = manager.GetListByParent(parentId);
                // 若是空的不用缓存,继续读取实体
                if (result != null)
                {
                    SetListCache(key, result);
                }
            }

            return(result);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// 从缓存获取获取实体
        /// </summary>
        /// <param name="id">主键</param>
        public static BaseAreaEntity GetObjectByCache(string id)
        {
            BaseAreaEntity result = null;

            System.Web.Caching.Cache cache = HttpRuntime.Cache;
            string cacheObject             = "Area";

            if (!string.IsNullOrEmpty(id))
            {
                cacheObject = "Area" + id;
            }
            if (cache != null && cache[cacheObject] == null)
            {
                lock (locker)
                {
                    if (cache != null && cache[cacheObject] == null)
                    {
                        BaseAreaManager manager = new DotNet.Business.BaseAreaManager(BaseAreaEntity.TableName);
                        result = manager.GetObject(id);
                        // 若是空的不用缓存,继续读取实体
                        if (result != null)
                        {
                            cache.Add(cacheObject, result, null, DateTime.Now.AddMinutes(5), TimeSpan.Zero, CacheItemPriority.Normal, null);
                            System.Console.WriteLine(System.DateTime.Now.ToString(BaseSystemInfo.DateTimeFormat) + " cache Area " + id);
                        }
                    }
                }
            }
            result = cache[cacheObject] as BaseAreaEntity;
            return(result);
        }
Ejemplo n.º 3
0
        public static List <BaseAreaEntity> GetProvinceByCache()
        {
            List <BaseAreaEntity> result = null;

            string key = "AreaProvince:";

            result = GetListCache(key);
            if (result == null)
            {
                BaseAreaManager manager = new DotNet.Business.BaseAreaManager();
                result = manager.GetProvince();
                // 若是空的不用缓存,继续读取实体
                if (result != null)
                {
                    SetListCache(key, result);
                }
            }

            return(result);
        }
Ejemplo n.º 4
0
        /// <summary>
        /// 从缓存获取获取实体
        /// </summary>
        /// <param name="id">主键</param>
        /// <returns>实体</returns>
        public static BaseAreaEntity GetObjectByCache(string id)
        {
            BaseAreaEntity result   = null;
            string         cacheKey = "Area:";

            if (!string.IsNullOrEmpty(id))
            {
                cacheKey = cacheKey + id;
            }

            result = GetCache(cacheKey);
            if (result == null || string.IsNullOrWhiteSpace(result.Id))
            {
                BaseAreaManager manager = new DotNet.Business.BaseAreaManager();
                result = manager.GetObject(id);
                // 若是空的不用缓存,继续读取实体
                if (result != null)
                {
                    SetCache(result);
                }
            }

            return(result);
        }