/// <summary> /// 验证码发送记录入库 /// </summary> /// <param name="sendResult">验证码发送结果</param> /// <param name="sendBody">发送的内容</param> /// <param name="guid">唯一标识</param> /// <param name="mobile">手机号</param> /// <param name="code">验证码</param> /// <returns></returns> private async Task <ApiResult> SaveSendHistoryAsync(ApiResult sendResult, string sendBody, string guid, string mobile, string code) { if (sendResult.code != ApiCode.成功) { return(ApiResult.Error(sendResult.msg)); } //用于校验验证码是否正确 await _cacheServices.AddAsync(guid, code, 60 * 10); //用于校验是否发送频繁 await _cacheServices.AddAsync(mobile, DateTime.Now.ToTimeStamp(), 60); _logger.LogDebug($"【发送验证码】内容:{sendBody},GUID:{guid},手机号:{mobile},验证码:{code},返回结果:{JsonHelper.Serialize(sendResult)}"); //保存到数据库中 await _validateCodeHistoryServices.InsertAsync(new Model.Entity.ValidateCodeHistory() { Address = mobile, Body = sendBody, IsSendOK = sendResult.code == ApiCode.成功, Result = JsonHelper.Serialize(sendResult), UUID = guid, Type = Model.Entity.SMSType.CellPhone, }); return(ApiResult.OK()); }
/// <summary> /// 代理访问域名加入缓存 /// </summary> /// <param name="domain"></param> /// <param name="agentId"></param> /// <returns></returns> public async Task <R> AddToCacheAsync(VisitDomain vdomain) { bool b = await _cache.ExistsAsync(vdomain.Domain.ToLower(), prefix); if (b) { return(R.Suc()); } b = await _cache.AddAsync(vdomain.Domain.ToLower(), vdomain.AgentId, prefix); if (!b) { return(R.Err("添加缓存失败")); } return(R.Suc()); }
public async Task <JsonResult> Get() { //var a=_cache.Get<Base_UserEntity>("test"); bool r = await _cache.AddAsync("test", "ichnb"); return(Json(ResponseResult.Execute(r))); //return new string[] { "value1", "value2" }; }
public async Task Invoke(HttpContext context) { var path = context.Request.Path; if (!path.StartsWithSegments("/images", System.StringComparison.OrdinalIgnoreCase) && !path.StartsWithSegments("/category/image", System.StringComparison.OrdinalIgnoreCase)) { await _next(context); return; } var fileName = Path.GetFileName(context.Request.Path.Value); var content = await _cacheService.GetAsync(fileName); if (content != null) { var contentType = _mimeHelper.GetMimeType(content); context.Response.ContentType = contentType; await context.Response.Body.WriteAsync(content); return; } var originalBody = context.Response.Body; byte[] responseContent; try { using (var memStream = new MemoryStream()) { context.Response.Body = memStream; await _next(context); memStream.Seek(0, SeekOrigin.Begin); responseContent = memStream.ToArray(); memStream.Seek(0, SeekOrigin.Begin); await memStream.CopyToAsync(originalBody); } } finally { context.Response.Body = originalBody; } if (!string.IsNullOrWhiteSpace(context.Response.ContentType) && context.Response.ContentType.StartsWith("image")) { await _cacheService.AddAsync(fileName, responseContent); } }
public async Task <string> Add() { var rand = StringHelper.RandomString(5); var addSuccess = await _cacheService.AddAsync(rand, rand); if (addSuccess) { return(rand); } else { return(false.ToString()); } }
public async Task <T> GetByIDAsync(Guid id) { T result = await _cacheService.GetAsync <T>(id.ToString()); if (result != null) { return(result); } result = await _dbSet.FindAsync(id); if (result != null) { await _cacheService.AddAsync(id.ToString(), result, _cacheDuration); } return(result); }
public async Task <List <RoleMenu> > GetlistAsync(long Id) { var list = await _cache.GetAsync <List <RoleMenu> >(Id.ToString(), prefix); if (list == null) { var vd = await _RoleMenuRep.QueryAsync <RoleMenu>("select * from `rolemenus` where `RoleId`=@RoleId", new { RoleId = Id }); if (vd != null) { await _cache.AddAsync(Id.ToString(), vd, prefix); return(vd.ToList()); } else { return(new List <RoleMenu>()); } } return(list); }
private static void onMessageRecieved(ChatMessage obj) { _cacheService.AddAsync(obj); }
public Task AddAsync(TKey key, TCacheValue cacheValue) { return(_cacheService.AddAsync(CreateCacheKey(key), cacheValue)); }
public async Task SendAsync(ChatMessage chatMessage) { await _queueService.SendAsync(chatMessage); await _cacheService.AddAsync(chatMessage); }
public async Task SendAsync(ToDoTask toDoTask) { await _queueService.SendAsync(toDoTask); await _cacheService.AddAsync(toDoTask); }
public async Task <bool> AddAsync(CacheItem cacheItem) { return(await _cacheService.AddAsync(cacheItem)); }
private static void OnMessageReceived(ToDoTask obj) { _cacheService.AddAsync(obj); }