You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

48 lines
1.3 KiB
C#

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<BaseCode>,IBaseCodeService
{
private readonly IMemoryCache _memoryCache;
public BaseCodeServiceImpl(Repository<BaseCode> rep, IMemoryCache memoryCache) : base(rep)
{
_memoryCache = memoryCache;
}
public void CreateBaseCode()
{
_rep.Context.CodeFirst.InitTables(typeof(BaseCode));
}
public List<BaseCode> QuListCache()
{
string key = "QuListCache";
if (_memoryCache.TryGetValue<List<BaseCode>>(key, out var list))
{
return list;
}
var entity = Query();
_memoryCache.Set(key, entity, TimeSpan.FromMinutes(5));
return entity;
}
/// <summary>
/// 根据Code去查询单个数据
/// </summary>
/// <param name="code"></param>
/// <returns></returns>
public BaseCode QueryCode(string code)
{
return Query(x => x.Code == code).First();
}
}
}