using HuanMeng.DotNetCore.CacheHelper;

using System;
using System.Collections.Generic;
using System.Linq;
using System.Linq.Expressions;
using System.Text;
using System.Threading.Tasks;

namespace CloudGaming.Code.Cache;


/// <summary>
/// 
/// </summary>
/// <typeparam name="T"></typeparam>
/// <param name="baseConfig"></param>
/// <param name="lockObj"></param>
/// <param name="cacheTime"></param>
/// <param name="expWhere"></param>
public class DataBaseEntityCache<T>(CacheBaseConfig baseConfig, object lockObj, int cacheTime = 36000, Expression<Func<T, bool>> expWhere = null)
    : CommonDataEntityCache<T>(lockObj, cacheTime) where T : class
{

    /// <summary>
    /// 缓存的key
    /// </summary>
    public override string key
    {
        get
        {
            return $"Cache:{baseConfig.AppConfig.Identifier}:CloudGaming:{typeof(T).Name}";
        }
    }
    /// <summary>
    /// 
    /// </summary>
    /// <returns></returns>
    public override List<T> GetDataList()
    {

        var dbSet = baseConfig.DbContext.Set<T>().AsNoTracking();
        if (dbSet == null)
        {
            return new List<T>();
        }
        if (expWhere != null)
        {
            dbSet = dbSet.Where(expWhere);
        }
        return dbSet.ToList();
    }
}
