using System; using System.Collections.Generic; using System.Linq; using Microsoft.Extensions.Caching.Memory; using SlnMesnac.Model.domain; using SlnMesnac.Repository.service.@base; namespace SlnMesnac.Repository.service { public class BaseCodeServiceImpl:BaseServiceImpl,IBaseCodeService { private readonly IMemoryCache _memoryCache; public BaseCodeServiceImpl(Repository rep, IMemoryCache memoryCache) : base(rep) { _memoryCache = memoryCache; } public void CreateBaseCode() { _rep.Context.CodeFirst.InitTables(typeof(BaseCode)); } public List QuListCache() { string key = "QuListCache"; if (_memoryCache.TryGetValue>(key, out var list)) { return list; } var entity = Query(); _memoryCache.Set(key, entity, TimeSpan.FromMinutes(5)); return entity; } /// /// 根据Code去查询单个数据 /// /// /// public BaseCode QueryCode(string code) { return Query(x => x.Code == code).First(); } } }