/// <summary>
        /// 引发数据变更的操作,通过改操作可以进行缓存及缓存依赖的通知
        /// </summary>
        /// <param name="entity"></param>
        public static void RaisePersistent(object entity)
        {
            if (entity == null)
            {
                throw new ArgumentNullException("entity");
            }
            var metadata = GetDefineMetadata(entity.GetType());

            if (metadata == null)
            {
                throw new PlatformException("无法获取对象的定义 {0}", entity.GetType().FullName);
            }

            // 如果启用缓存,则通知过期
            if (metadata.IsCacheable)
            {
                var    cacheKey = metadata.GetCacheKey(entity);
                ICache cache    = GetCacher(metadata);
                cache.Remove(metadata.EntityType, cacheKey);
            }

            // 更新依赖缓存的时间戳
            var depends = metadata.GetCacheRegionKeys(entity);

            if (depends.Count > 0)
            {
                var    time        = NetworkTime.Now.Ticks;
                ICache dependCache = RepositoryFramework.GetCacherForCacheRegion();
                var    items       = depends.Select(o => new CacheItem <long>(o, time)).ToList();
                dependCache.SetBatch(items, DateTime.MaxValue);
            }
        }
Beispiel #2
0
        bool CheckEntity(TKey key, IQueryTimestamp data)
        {
            if (data == null)
            {
                return(true);
            }

            var cdd = new CacheDependDefine();

            dependAction(cdd, key);
            var keys = cdd.GetCacheKey();

            ICache dependCache = RepositoryFramework.GetCacherForCacheRegion();
            var    values      = dependCache.GetBatch <long>(keys);
            var    isValid     = values.Count() == 0 || values.All(o => o < data.Timestamp);

            if (!isValid)
            {
                RemoveCache(key);
            }

            return(isValid);
        }