Пример #1
0
 /// <summary>
 /// 数据库删除实体后自动调用该方法
 /// </summary>
 /// <param name="entity"></param>
 protected virtual void OnDeleted(TEntity entity)
 {
     #region 处理缓存
     if (RealTimeCacheHelper.EnableCache)
     {
         //递增实体缓存版本
         RealTimeCacheHelper.IncreaseEntityCacheVersion(entity.EntityId);
         //更新列表缓存版本
         RealTimeCacheHelper.IncreaseListCacheVersion(entity);
         cacheService.MarkDeletion(RealTimeCacheHelper.GetCacheKeyOfEntity(entity.EntityId), entity, CachingExpirationType.SingleObject);
     }
     #endregion
 }
Пример #2
0
        /// <summary>
        /// 数据库新增实体后自动调用该方法
        /// </summary>
        protected virtual void OnInserted(TEntity entity)
        {
            #region 处理缓存
            if (RealTimeCacheHelper.EnableCache)
            {
                //更新列表缓存版本
                RealTimeCacheHelper.IncreaseListCacheVersion(entity);

                if (RealTimeCacheHelper.PropertyNameOfBody != null)
                {
                    string body = RealTimeCacheHelper.PropertyNameOfBody.GetValue(entity, null) as string;
                    cacheService.Add(RealTimeCacheHelper.GetCacheKeyOfEntityBody(entity.EntityId), body, RealTimeCacheHelper.CachingExpirationType);

                    //启用实体正文缓存时,不在实体缓存中存储实体正文
                    RealTimeCacheHelper.PropertyNameOfBody.SetValue(entity, null, null);
                }
                cacheService.Add(RealTimeCacheHelper.GetCacheKeyOfEntity(entity.EntityId), entity, RealTimeCacheHelper.CachingExpirationType);
            }
            #endregion
        }