增加redis缓存

This commit is contained in:
2024-07-12 18:55:07 +08:00
parent 6a5ef1226c
commit 6deb400144
5 changed files with 19 additions and 3 deletions
+1
View File
@@ -14,6 +14,7 @@
<PackageReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Design" Version="8.0.2" /> <PackageReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Design" Version="8.0.2" />
<PackageReference Include="MimeKit" Version="4.6.0" /> <PackageReference Include="MimeKit" Version="4.6.0" />
<PackageReference Include="MySql.Data" Version="8.4.0" /> <PackageReference Include="MySql.Data" Version="8.4.0" />
<PackageReference Include="NewLife.Redis" Version="5.7.2024.701" />
<PackageReference Include="NewLife.XCode" Version="11.13.2024.606" /> <PackageReference Include="NewLife.XCode" Version="11.13.2024.606" />
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" /> <PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
<PackageReference Include="Senparc.NeuChar" Version="2.4.1" /> <PackageReference Include="Senparc.NeuChar" Version="2.4.1" />
+12 -2
View File
@@ -18,16 +18,19 @@ using Newtonsoft.Json;
using COMCMS.Web.Common; using COMCMS.Web.Common;
using Microsoft.AspNetCore.Hosting; using Microsoft.AspNetCore.Hosting;
using System.Text.RegularExpressions; using System.Text.RegularExpressions;
using NewLife.Caching;
namespace COMCMS.Web.Controllers namespace COMCMS.Web.Controllers
{ {
public class HomeController : HomeBaseController public class HomeController : HomeBaseController
{ {
private IWebHostEnvironment _env; private IWebHostEnvironment _env;
private readonly ICacheProvider _cacheProvider;
public HomeController(IWebHostEnvironment env) public HomeController(IWebHostEnvironment env,ICacheProvider cacheProvider)
{ {
_env = env; _env = env;
_cacheProvider = cacheProvider;
} }
#region 首页 #region 首页
@@ -455,6 +458,7 @@ namespace COMCMS.Web.Controllers
return View(); return View();
} }
#endregion #endregion
#region 测试 #region 测试
public IActionResult Test() public IActionResult Test()
{ {
@@ -473,7 +477,13 @@ namespace COMCMS.Web.Controllers
string result = $"t1:{t1}; t2:{t2}; t3:{t3}; t4:{t4}; t5:{t5}; t6:{t6}"; string result = $"t1:{t1}; t2:{t2}; t3:{t3}; t4:{t4}; t5:{t5}; t6:{t6}";
return Content(result);
_cacheProvider.Cache.Add("test", "test", 60);
string a = _cacheProvider.Cache.Get<string>("test");
return Content(result+";cache:"+ a);
} }
#endregion #endregion
} }
+3
View File
@@ -23,6 +23,8 @@ using Microsoft.Extensions.Hosting;
using Microsoft.Extensions.Options; using Microsoft.Extensions.Options;
using Microsoft.Extensions.WebEncoders; using Microsoft.Extensions.WebEncoders;
using Microsoft.IdentityModel.Tokens; using Microsoft.IdentityModel.Tokens;
using NewLife.Caching;
using NewLife.Caching.Services;
using Newtonsoft.Json.Serialization; using Newtonsoft.Json.Serialization;
using Senparc.CO2NET; using Senparc.CO2NET;
using Senparc.CO2NET.Cache; using Senparc.CO2NET.Cache;
@@ -65,6 +67,7 @@ namespace COMCMS.Web
options.Cookie.HttpOnly = true; options.Cookie.HttpOnly = true;
}); });
services.AddSingleton<ICacheProvider, RedisCacheProvider>();
//部分系统配置 //部分系统配置
services.Configure<SystemSetting>(Configuration.GetSection("SystemSetting")); services.Configure<SystemSetting>(Configuration.GetSection("SystemSetting"));
+1
View File
@@ -5,6 +5,7 @@
"Default": "Warning" "Default": "Warning"
} }
}, },
"RedisCache": "server=127.0.0.1;password=;db=2",
"SystemSetting": { "SystemSetting": {
"FileAllowedExtensions": "zip,rar,7z,doc,docx,xls,xlsx,ppt,pptx,csv,pdf,txt,gz,gzip,gif,png,jpg,jpeg,bmp,avi,fla,flv,swf,mp4,mp3,mov,mid,mpg,mpeg,rm,rmvb,wma,wav,wmv", "FileAllowedExtensions": "zip,rar,7z,doc,docx,xls,xlsx,ppt,pptx,csv,pdf,txt,gz,gzip,gif,png,jpg,jpeg,bmp,avi,fla,flv,swf,mp4,mp3,mov,mid,mpg,mpeg,rm,rmvb,wma,wav,wmv",
"ImageAllowedExtensions": "gif,png,jpg,jpeg,bmp", "ImageAllowedExtensions": "gif,png,jpg,jpeg,bmp",
+2 -1
View File
@@ -6,7 +6,8 @@
CKEDITOR.editorConfig = function( config ) { CKEDITOR.editorConfig = function( config ) {
// Define changes to default configuration here. For example: // Define changes to default configuration here. For example:
//config.language = 'zh-cn'; //config.language = 'zh-cn';
// config.uiColor = '#AADC6E'; // config.uiColor = '#AADC6E';
config.versionCheck = false;
config.baseHref = "http://" + location.host; config.baseHref = "http://" + location.host;
config.filebrowserImageUploadUrl = '/AdminCP/Upload/CKUploadImage?action=uploadimg'; config.filebrowserImageUploadUrl = '/AdminCP/Upload/CKUploadImage?action=uploadimg';
config.filebrowserUploadUrl = '/AdminCP/Upload/CKUploadFile?action=uploadfile'; config.filebrowserUploadUrl = '/AdminCP/Upload/CKUploadFile?action=uploadfile';