Exemplo n.º 1
0
        /// <summary>
        /// 更新缓存对象,不存在则添加到缓存
        /// </summary>
        /// <param name="model"></param>
        public void UpadteCacheObject(T model)
        {
            if (model == null)
            {
                return;
            }
            object key = ReflectUtil.GetProperty(model, "ID");

            if (key == null)
            {
                throw new Exception("对象不存在ID属性,或者ID属性为null");
            }
            ;
            int IntKey = 0;

            try
            {
                Convert.ToInt32(key);
            }
            catch
            {
                throw new Exception("对象的ID属性不能转化为整型");
            }
            string CacheKey = GetCacheKey(IntKey);

            DataCache.RemoveCache(CacheKey);
            int Timeout = ConfigHelper.GetConfigInt("CacheTimeout");

            DataCache.SetCache(CacheKey, model, DateTime.Now.AddMinutes(Timeout), TimeSpan.Zero);
        }