diff --git a/src/CloudGaming/Code/CloudGaming.Code/AppExtend/CloudGamingBase.cs b/src/CloudGaming/Code/CloudGaming.Code/AppExtend/CloudGamingBase.cs
index 0dd3c77..439e2b4 100644
--- a/src/CloudGaming/Code/CloudGaming.Code/AppExtend/CloudGamingBase.cs
+++ b/src/CloudGaming/Code/CloudGaming.Code/AppExtend/CloudGamingBase.cs
@@ -1,5 +1,6 @@
using AutoMapper;
+using CloudGaming.Code.Cache;
using CloudGaming.Code.DataAccess;
using HuanMeng.DotNetCore.JwtInfrastructure.Interface;
@@ -13,7 +14,7 @@ using StackExchange.Redis;
namespace CloudGaming.Code.AppExtend
{
///
- /// bll基础类
+ /// BLL 基础类
///
public class CloudGamingBase : BLLBase
{
@@ -24,7 +25,7 @@ namespace CloudGaming.Code.AppExtend
#region 数据库
private DAO _dao;
///
- /// dao 数据库
+ /// DAO 数据库
///
public override DAO Dao
{
@@ -41,11 +42,9 @@ namespace CloudGaming.Code.AppExtend
#region 映射
private IMapper _mapper;
-
///
- /// dto映射
+ /// DTO 映射
///
- //[FromServices]
public virtual IMapper Mapper
{
get
@@ -56,14 +55,15 @@ namespace CloudGaming.Code.AppExtend
}
return _mapper;
}
- set { _mapper = value; }
+ set
+ {
+ _mapper = value;
+ }
}
#endregion
- #region AppConfig
- ///
- ///
- ///
- private AppConfig? appConfig;
+
+ #region AppConfig 配置
+ private AppConfig _appConfig;
///
/// AppConfig 配置
///
@@ -71,17 +71,17 @@ namespace CloudGaming.Code.AppExtend
{
get
{
- if (appConfig == null)
+ if (_appConfig == null)
{
- appConfig = _serviceProvider.GetService();
+ _appConfig = _serviceProvider.GetService();
}
- return appConfig;
+ return _appConfig;
}
}
#endregion
- #region 请求信息
- private IHttpContextAccessor _HttpContextAccessor;
+ #region 请求信息
+ private IHttpContextAccessor _httpContextAccessor;
///
/// HttpContextAccessor
///
@@ -89,20 +89,19 @@ namespace CloudGaming.Code.AppExtend
{
get
{
- if (_HttpContextAccessor == null)
+ if (_httpContextAccessor == null)
{
- _HttpContextAccessor = _serviceProvider.GetRequiredService();
+ _httpContextAccessor = _serviceProvider.GetRequiredService();
}
- return _HttpContextAccessor;
+ return _httpContextAccessor;
}
}
#endregion
- #region http请求
- private IHttpClientFactory? _httpClientFactory;
-
+ #region HTTP 请求
+ private IHttpClientFactory _httpClientFactory;
///
- /// http请求
+ /// HttpClientFactory
///
public IHttpClientFactory HttpClientFactory
{
@@ -117,11 +116,10 @@ namespace CloudGaming.Code.AppExtend
}
#endregion
- #region JWT管理
-
+ #region JWT 管理
private IJwtAuthManager _jwtAuthManager;
///
- /// jwt管理
+ /// JWT 管理
///
public IJwtAuthManager JwtAuthManager
{
@@ -136,12 +134,13 @@ namespace CloudGaming.Code.AppExtend
}
#endregion
-
#region 日志
- private ILogger? _logger;
- public ILogger _Logger
+ private ILogger _logger;
+ ///
+ /// 日志
+ ///
+ public ILogger Logger
{
-
get
{
if (_logger == null)
@@ -154,9 +153,9 @@ namespace CloudGaming.Code.AppExtend
#endregion
#region Redis
- private IDatabase? _redis;
+ private IDatabase _redis;
///
- /// 妙语实现类
+ /// Redis 缓存
///
public IDatabase RedisCache
{
@@ -170,5 +169,23 @@ namespace CloudGaming.Code.AppExtend
}
}
#endregion
+
+ #region 缓存
+ private CloudGamingCache _cache;
+ ///
+ /// 缓存
+ ///
+ public CloudGamingCache Cache
+ {
+ get
+ {
+ if (_cache == null)
+ {
+ _cache = new CloudGamingCache(this);
+ }
+ return _cache;
+ }
+ }
+ #endregion
}
}
diff --git a/src/CloudGaming/Code/CloudGaming.Code/Cache/CloudGamingCache.cs b/src/CloudGaming/Code/CloudGaming.Code/Cache/CloudGamingCache.cs
index 3dde28f..64e64f1 100644
--- a/src/CloudGaming/Code/CloudGaming.Code/Cache/CloudGamingCache.cs
+++ b/src/CloudGaming/Code/CloudGaming.Code/Cache/CloudGamingCache.cs
@@ -8,63 +8,59 @@ namespace CloudGaming.Code.Cache
///
/// 缓存数据表
///
- ///
- public class CloudGamingCache(CloudGamingBase gamingBase)
+ public class CloudGamingCache
{
- #region 图片缓存表
-
- ///
- /// 图片缓存表
- ///
- public CommonDataEntityCache? ImageConfigCache { get; set; }
- ///
- /// 图片
- ///
- public List ImageConfigList
+ private readonly CloudGamingBase _gamingBase;
+
+ public CloudGamingCache(CloudGamingBase gamingBase)
{
- get
- {
- if (ImageConfigCache == null)
- {
- ImageConfigCache = CloudGamingCacheExtend.GetDataEntityCache(gamingBase);
- }
- return ImageConfigCache.DataList ?? new List();
- }
+ _gamingBase = gamingBase;
}
+
+ #region 通用缓存获取方法
+
+ ///
+ /// 通用缓存获取方法,适用于所有类型
+ ///
+ private List GetCacheList(ref CommonDataEntityCache? cache, Expression>? expWhere = null) where T : class
+ {
+ if (cache == null)
+ {
+ cache = CloudGamingCacheExtend.GetDataEntityCache(_gamingBase, expWhere);
+ }
+ return cache.DataList ?? new List();
+ }
+
+ #endregion
+
+ #region 图片缓存表
+
+ private CommonDataEntityCache? _appImageCache;
+
+ ///
+ /// 图片缓存列表
+ ///
+ public List AppImageList => GetCacheList(ref _appImageCache);
+
#endregion
#region 配置缓存表
-
- ///
- /// 配置缓存表
- ///
- public CommonDataEntityCache? AppConfigCache { get; set; }
+
+ private CommonDataEntityCache? _appConfigCache;
///
- /// 配置
+ /// 配置缓存列表
///
- public List AppConfigList
- {
- get
- {
- if (AppConfigCache == null)
- {
- AppConfigCache = CloudGamingCacheExtend.GetDataEntityCache(gamingBase);
- }
- return AppConfigCache.DataList ?? new List();
- }
- }
+ public List AppConfigList => GetCacheList(ref _appConfigCache);
+
#endregion
}
///
- /// 游戏
+ /// 游戏缓存扩展
///
public static class CloudGamingCacheExtend
{
- ///
- /// 缓存锁字典
- ///
private static readonly ConcurrentDictionary ExtCacheLockList = new ConcurrentDictionary();
private static readonly ConcurrentDictionary GameCacheLockList = new ConcurrentDictionary();
private static readonly ConcurrentDictionary AppCacheLockList = new ConcurrentDictionary();
@@ -78,12 +74,12 @@ namespace CloudGaming.Code.Cache
static CloudGamingCacheExtend()
{
NamespaceMapping = new Dictionary cacheList, AppDataBaseType dbType)>
- {
- { "CloudGaming.GameModel.Db.Db_Ext", (ExtCacheLockList, AppDataBaseType.Ext) },
- { "CloudGaming.GameModel.Db.Db_Game", (GameCacheLockList, AppDataBaseType.Game) },
- { "CloudGaming.Model.DbSqlServer.Db_Phone", (AppCacheLockList, AppDataBaseType.App) },
- { "CloudGaming.Model.DbSqlServer.Db_User", (UserCacheLockList, AppDataBaseType.User) }
- };
+ {
+ { "CloudGaming.GameModel.Db.Db_Ext", (ExtCacheLockList, AppDataBaseType.Ext) },
+ { "CloudGaming.GameModel.Db.Db_Game", (GameCacheLockList, AppDataBaseType.Game) },
+ { "CloudGaming.Model.DbSqlServer.Db_Phone", (AppCacheLockList, AppDataBaseType.App) },
+ { "CloudGaming.Model.DbSqlServer.Db_User", (UserCacheLockList, AppDataBaseType.User) }
+ };
}
///
@@ -113,7 +109,7 @@ namespace CloudGaming.Code.Cache
{
return cacheList.GetOrAdd(typeLock, _ =>
{
- Log("没有找到锁对象==>" + typeLock.Name);
+ Log($"没有找到锁对象 ==> {typeLock.Name}");
return new object();
});
}
@@ -138,9 +134,8 @@ namespace CloudGaming.Code.Cache
///
private static void Log(string message)
{
- // 这里可以替换为更好的日志记录系统,例如 NLog, Serilog 等
+ // 替换为其他日志记录系统,例如 NLog, Serilog 等
Console.WriteLine(message);
}
}
-
}
diff --git a/src/CloudGaming/Model/CloudGaming.GameModel/Db/Db_Ext/CloudGamingCBTContext.cs b/src/CloudGaming/Model/CloudGaming.GameModel/Db/Db_Ext/CloudGamingCBTContext.cs
index 80de259..47f9781 100644
--- a/src/CloudGaming/Model/CloudGaming.GameModel/Db/Db_Ext/CloudGamingCBTContext.cs
+++ b/src/CloudGaming/Model/CloudGaming.GameModel/Db/Db_Ext/CloudGamingCBTContext.cs
@@ -52,7 +52,7 @@ public partial class CloudGamingCBTContext : DbContext
///
/// 图片列表
///
- public virtual DbSet T_Image_Config { get; set; }
+ public virtual DbSet T_App_Image { get; set; }
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
=> optionsBuilder.UseSqlServer("Server=192.168.1.17;Database=CloudGamingCBT;User Id=sa;Password=Dbt@com@123;TrustServerCertificate=true;");
@@ -94,7 +94,7 @@ public partial class CloudGamingCBTContext : DbContext
});
- modelBuilder.Entity(entity =>
+ modelBuilder.Entity(entity =>
{
entity.HasKey(e => e.Id).HasName("PK_T_VL_UI_IMAGES");
diff --git a/src/CloudGaming/Model/CloudGaming.GameModel/Db/Db_Ext/T_Image_Config.cs b/src/CloudGaming/Model/CloudGaming.GameModel/Db/Db_Ext/T_App_Image.cs
similarity index 93%
rename from src/CloudGaming/Model/CloudGaming.GameModel/Db/Db_Ext/T_Image_Config.cs
rename to src/CloudGaming/Model/CloudGaming.GameModel/Db/Db_Ext/T_App_Image.cs
index 1922715..7192197 100644
--- a/src/CloudGaming/Model/CloudGaming.GameModel/Db/Db_Ext/T_Image_Config.cs
+++ b/src/CloudGaming/Model/CloudGaming.GameModel/Db/Db_Ext/T_App_Image.cs
@@ -5,9 +5,9 @@ namespace CloudGaming.GameModel.Db.Db_Ext;
///
/// 图片列表
///
-public partial class T_Image_Config
+public partial class T_App_Image
{
- public T_Image_Config() { }
+ public T_App_Image() { }
public virtual int Id { get; set; }
diff --git a/src/CloudGaming/Model/CloudGaming.GameModel/Db/Db_Ext/T_Config.cs b/src/CloudGaming/Model/CloudGaming.GameModel/Db/Db_Ext/T_Config.cs
deleted file mode 100644
index ec7c5c1..0000000
--- a/src/CloudGaming/Model/CloudGaming.GameModel/Db/Db_Ext/T_Config.cs
+++ /dev/null
@@ -1,47 +0,0 @@
-using System;
-
-namespace CloudGaming.GameModel.Db.Db_Ext;
-
-///
-/// App配置
-///
-public partial class T_Config
-{
- public T_Config() { }
-
- public virtual int Id { get; set; }
-
- public virtual int? ConfigType { get; set; }
-
- public virtual int? ConfigId { get; set; }
-
- public virtual bool? IsShow { get; set; }
-
- public virtual string? ShowName { get; set; }
-
- public virtual string? Desc { get; set; }
-
- public virtual DateTime? UpdateTime { get; set; }
-
- public virtual DateTime? CreatTime { get; set; }
-
- public virtual int? ConfigNum { get; set; }
-
- public virtual int? ConfigNum2 { get; set; }
-
- public virtual string? ConfigStr { get; set; }
-
- public virtual string? BossId { get; set; }
-
- public virtual string? Plat { get; set; }
-
- ///
- /// 州 例:亚洲
- ///
- public virtual string? Continent { get; set; }
-
- ///
- /// 国家 例:中国
- ///
- public virtual string? CountryName { get; set; }
-}