据说是最全的asp.NetCore3.1系统自带缓存Imemcache的滑动绝对文件依赖的测试使用
2021-01-17 11:16
标签:load dom code ESS memory dos font 帮助 环境 个人测试环境为:Asp.net coe 3.1 WebApi 1:封装自定义的cacheHelper帮助类,部分代码 2:在startUp类中 注册方法: services.AddMemoryCache();//注册使用缓存 3:测试代码 4:文件依赖过期的测试效果截图: 4.1:当文件没有被修改,多次刷新请求,缓存的数据没有变化,到达了效果 4.2:当文件内容有修改,重新请求接口发现缓存的数据有变化,到达了预期的效果 5: 其他的测试也ok,这里就不贴出来了,下面为全部的cacheHelper帮助类的代码: 6:进一步使用到自定义的配置文件中 7:模型 8:测试完整代码: 据说是最全的asp.NetCore3.1系统自带缓存Imemcache的滑动绝对文件依赖的测试使用 标签:load dom code ESS memory dos font 帮助 环境 原文地址:https://www.cnblogs.com/Fengge518/p/13366351.html 1 public static void SetCacheByFile
[HttpGet, Route("DocacheByFIle")]
public ApiResult DoSystemFileCacheTest()
{
ApiResult result = new ApiResult();
try
{
string time = SystemCacheHelper.GetByCachestring>("Filecache");
if (string.IsNullOrEmpty(time))
{
var gettime = "你好峰哥,我是文件依赖的缓存" + DateTime.Now.ToString();
SystemCacheHelper.SetCacheByFilestring>("Filecache", gettime);
time = gettime;
}
result.data = time;
result.code = statuCode.success;
result.message = "获取cache数据成功!";
}
catch (Exception ex)
{
result.message = "发生异常:" + ex.Message;
}
return result;
}
1 using System;
2 using System.Collections.Generic;
3 using System.Linq;
4 using System.Threading.Tasks;
5
6 namespace ZRFCoreTestMongoDB.Commoms
7 {
8 using Microsoft.Extensions.Caching.Memory;
9 using Microsoft.Extensions.Options;
10 using ZRFCoreTestMongoDB.Model;
11 ///
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
namespace ZRFCoreTestMongoDB.Commoms
{
using ZRFCoreTestMongoDB.Model;
using Microsoft.Extensions.Configuration;
public class AppJsonHelper
{
public static JwtConfigModel InitJsonModel()
{
string key = "key_myjsonfilekey";
JwtConfigModel cachemodel = SystemCacheHelper.GetByCache
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
namespace ZRFCoreTestMongoDB.Model
{
public class JwtConfigModel
{
public string TockenSecrete { get; set; }
public string Issuer { get; set; }
public string Audience { get; set; }
}
}
1 using System;
2 using System.Collections.Generic;
3 using System.Linq;
4 using System.Threading.Tasks;
5
6 namespace ZRFCoreTestMongoDB.Controllers
7 {
8 using Microsoft.AspNetCore.Authorization;
9 using Microsoft.AspNetCore.Mvc.Filters;
10 using Microsoft.AspNetCore.Mvc;
11 using ZRFCoreTestMongoDB.Model;
12 using ZRFCoreTestMongoDB.Commoms;
13 [ApiController]
14 [Route("api/[Controller]")]
15 public class MyJwtTestController : ControllerBase
16 {
17 private readonly JwtConfigModel _jsonmodel;
18 public MyJwtTestController()
19 {
20 _jsonmodel = AppJsonHelper.InitJsonModel();
21 }
22 [HttpGet, Route("jsonmodel")]
23 public ApiResult DoMyselfJsonTest()
24 {
25 ApiResult result = new ApiResult();
26 try
27 {
28 result.data = _jsonmodel;
29 result.code = statuCode.success;
30 result.message = "获取数据成功!";
31 }
32 catch (Exception ex)
33 {
34 result.message = "发生异常:" + ex.Message;
35 }
36 return result;
37 }
38 [HttpGet, Route("testcache")]
39 public ApiResult DoSystemCacheTest()
40 {
41 ApiResult result = new ApiResult();
42 try
43 {
44 string time = SystemCacheHelper.GetByCachestring>("nowtime");
45 if (string.IsNullOrEmpty(time))
46 {
47 var gettime = "为:" + DateTime.Now.ToString();
48 SystemCacheHelper.SetCachestring>("nowtime", gettime, minutes: 1);
49 time = gettime;
50 }
51 result.data = time;
52 result.code = statuCode.success;
53 result.message = "获取cache数据成功!";
54 }
55 catch (Exception ex)
56 {
57 result.message = "发生异常:" + ex.Message;
58 }
59 return result;
60 }
61 [HttpGet, Route("DocacheByFIle")]
62 public ApiResult DoSystemFileCacheTest()
63 {
64 ApiResult result = new ApiResult();
65 try
66 {
67 string time = SystemCacheHelper.GetByCachestring>("Filecache");
68 if (string.IsNullOrEmpty(time))
69 {
70 var gettime = "你好峰哥,我是文件依赖的缓存" + DateTime.Now.ToString();
71 SystemCacheHelper.SetCacheByFilestring>("Filecache", gettime);
72 time = gettime;
73 }
74 result.data = time;
75 result.code = statuCode.success;
76 result.message = "获取cache数据成功!";
77 }
78 catch (Exception ex)
79 {
80 result.message = "发生异常:" + ex.Message;
81 }
82 return result;
83 }
84 }
85 }
1 using System;
2 using System.Collections.Generic;
3 using System.Linq;
4 using System.Threading.Tasks;
5
6 namespace ZRFCoreTestMongoDB.Commoms
7 {
8 using ZRFCoreTestMongoDB.Model;
9 using Microsoft.Extensions.Configuration;
10 public class AppJsonHelper
11 {
12 public static JwtConfigModel InitJsonModel()
13 {
14 string key = "key_myjsonfilekey";
15 JwtConfigModel cachemodel = SystemCacheHelper.GetByCache
文章标题:据说是最全的asp.NetCore3.1系统自带缓存Imemcache的滑动绝对文件依赖的测试使用
文章链接:http://soscw.com/essay/43175.html