public override bool ProcessSource() { var metadata = DefineMetadata; Invocation.Proceed(); ICache queryCache = RepositoryFramework.GetCacherForQuery(metadata); ICache cache = RepositoryFramework.GetCacher(metadata); //IList接口 TEntity item = (TEntity)Invocation.ReturnValue; if (item != null) { var ta = TypeAccessor.GetAccessor(metadata.EntityType); var idGetter = ta.GetPropertyGetter(metadata.IdMember.Name); var spec = (ISpecification <TEntity>)Invocation.Arguments[0]; if (spec == null) { throw new ArgumentException("第一个参数类型必须为 ISpecification<TEntity>"); } //加入缓存 cache.Set(metadata.GetCacheKey(item), metadata.CloneEntity(item), 1200); queryCache.Set(CacheKey, new ListCacheData(new object[] { idGetter(item) }) { ShardParams = spec.ShardParams }); } return(item != null); }
public override bool ProcessSource() { var metadata = DefineMetadata; Invocation.Proceed(); ICache queryCache = RepositoryFramework.GetCacherForQuery(metadata); ICache cache = RepositoryFramework.GetCacher(metadata); //IList接口 PagingResult <TEntity> paging = (PagingResult <TEntity>)Invocation.ReturnValue; var ta = TypeAccessor.GetAccessor(metadata.EntityType); var idGetter = ta.GetPropertyGetter(metadata.IdMember.Name); var spec = (ISpecification <TEntity>)Invocation.Arguments[0]; if (spec == null) { throw new ArgumentException("第一个参数类型必须为 ISpecification<TEntity>"); } //加入缓存 cache.SetBatch(paging.Items.Cast <object>().Select(o => new CacheItem <object>(metadata.GetCacheKey(o), metadata.CloneEntity(o))), 1200); queryCache.Set(CacheKey, new PagingCacheData(paging.Items.Select(o => idGetter(o))) { ShardParams = spec.ShardParams, TotalCount = paging.TotalCount }); return(true); }
public override IQueryTimestamp GetCacheData() { return(RepositoryFramework.GetCacherForQuery(DefineMetadata).Get <ListCacheData>(CacheKey)); }