ABP 使用cache缓存
using Abp.Application.Services.Dto;
using Abp.Runtime.Caching;
using Microsoft.Extensions.Configuration;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using Newtonsoft.Json.Schema;
using Senparc.CO2NET.HttpUtility;
using Senparc.Weixin.CommonAPIs.ApiHandlerWapper;
using Senparc.Weixin.MP.Containers;
using Senparc.Weixin.MP.Entities;
using System;
using System.Collections.Generic;
using System.Configuration;
using System.Net.Http;
using System.Net.Http.Headers;
using System.Text;
using System.Threading.Tasks; namespace AbpProject.WeiXinMPCache
{
public class MPCacheAppService : AbpProjectAppServiceBase, IMPCacheAppService
{
/// <summary>
/// appid
/// </summary>
private readonly string AppIdSAddress = "WeiXinMP:AppID";
/// <summary>
/// appsecret
/// </summary>
private readonly string AppSecretAddress = "WeiXinMP:AppSecret";
/// <summary>
/// 获取token的路径
/// </summary>
private readonly string AccTokenUrl = "https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid={0}&secret={1}"; private readonly ICacheManager _cacheManager;
private readonly IConfiguration _appConfiguration; public MPCacheAppService(IConfiguration appConfiguration, ICacheManager cacheManager)
{
_appConfiguration = appConfiguration;
_cacheManager = cacheManager;
} /// <summary>
/// 获取公众微信号的token
/// </summary>
/// <returns></returns>
public async Task<string> GetAccessToken()
{
var acctoken = await _cacheManager.GetCache("WeiXinMP").GetOrDefaultAsync("AccessToken");
if (acctoken == null || string.IsNullOrEmpty(acctoken.ToString()))
{
var appId = _appConfiguration[AppIdSAddress];
var appSecret = _appConfiguration[AppSecretAddress];
var url = string.Format(AccTokenUrl, appId, appSecret);
var result = HttpClientHelper<AccessTokenResult>.Get(url,new AccessTokenResult());
if (result != null)
{
await _cacheManager.GetCache("WeiXinMP").SetAsync("AccessToken", result.access_token, TimeSpan.FromHours());
return result.access_token;
}
}
return acctoken.ToString();
} }
}
ABP 使用cache缓存的更多相关文章
- 缓存与ABP Redis Cache
缓存与ABP Redis Cache 为什么要用缓存 为什么要用缓存呢,说缓存之前先说使用缓存的优点. 减少寄宿服务器的往返调用(round-trips). 如果缓存在客户端或是代理,将减少对服务器的 ...
- ABP理论学习之缓存Caching
返回总目录 本篇目录 介绍 ICacheManager ICache ITypedCache 配置 介绍 ABP提供了缓存的抽象,它内部使用了这个缓存抽象.虽然默认的实现使用了MemoryCache, ...
- abp使用redis缓存
利用NuGet程序包管理程序,添加 Abp.RedisCache 在 xxxx.Web.Core 项目的Module中注册Redis 在刚才上面这个类文件头部注册Redis组件 在Web.config ...
- 注释驱动的 Spring cache 缓存介绍
概述 Spring 3.1 引入了激动人心的基于注释(annotation)的缓存(cache)技术,它本质上不是一个具体的缓存实现方案(例如 EHCache 或者 OSCache),而是一个对缓存使 ...
- Windows Azure Cloud Service (43) 使用Azure In-Role Cache缓存(2)Dedicated Role
<Windows Azure Platform 系列文章目录> Update 2016-01-12 https://azure.microsoft.com/zh-cn/documentat ...
- [转]注释驱动的 Spring cache 缓存介绍
原文:http://www.ibm.com/developerworks/cn/opensource/os-cn-spring-cache/ 概述 Spring 3.1 引入了激动人心的基于注释(an ...
- paip.cache 缓存架构以及性能提升总结
paip.cache 缓存架构以及性能提升总结 1 缓存架构以及性能(贯穿读出式(LookThrough) 旁路读出式(LookAside) 写穿式(WriteThrough) 回写式 ...
- Cache缓存对象缓存对象
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="DemoCache.aspx ...
- 注释驱动的 Spring cache 缓存介绍--转载
概述 Spring 3.1 引入了激动人心的基于注释(annotation)的缓存(cache)技术,它本质上不是一个具体的缓存实现方案(例如 EHCache 或者 OSCache),而是一个对缓存使 ...
随机推荐
- 网络编程(二)--TCP协议、基于tcp协议的套接字socket
一.TCP协议(Transmission Control Protocol 传输控制协议) 1.可靠传输,TCP数据包没有长度限制,理论上可以无限长,但是为了保证网络的效率,通常TCP数据包的长度不会 ...
- MySQL使用alter修改表的结构
SQL语句 DLL 数据定义语言 create,drop DML 数据操纵语言 insert,delete,select,upda ...
- 国内加速访问 GitHub
国内加速访问 GitHub 本文原始地址:https://sitoi.cn/posts/23395.html 中国访问 GitHub 的速度不忍直视,那就叫一个慢! Q: 为什么访问速度会很慢? A: ...
- ansible自动化运维03
ansible自动化运维常用模块 常用模块实现的功能:安装软件包:修改配置文件:创建程序用户组:创建目录,并修改所属和权限:挂载:启动服务:测试. command模块: shell模块: 注意:com ...
- Anaconda 安装 tensorflow 和 keras
说明:此操作是在 Anaconda Prompt 窗口完成的 CPU版 tensorflow 的安装. 1.用 conda 创建虚拟环境 tensorflow python=3.6 conda cre ...
- msyql常用命令
1.创建.删除数据库 create database dbname; drop database dbname; 2.选择某一个数据库 use dbname; 3.显示所有表 show tables; ...
- 《MySQL性能优化篇》阅读笔记
建表的时候,不要用null赋默认值,如:字符串的设置'',数据类型的设为0,不要将null设为默认值. 在MySQL中没有 full [outer] join,用union代替 各种 JOIN SQL ...
- Speech Enhancement via Deep Spectrum Image Translation Network
文中提出了一种深度网络来解决单通道语音增强问题. 链接:https://arxiv.org/abs/1911.01902 简介 因为背景噪声和混响的存在,录音通常会被扭曲,会对后端的语音识别等技术产生 ...
- NOIP动态规划大合集
1.前言 NOIP2003-2014动态规划题目大合集,有简单的也有难的(对于我这种动态规划盲当然存在难的),今天就把这些东西归纳一下,做一个比较全面的总结,方便对动态规划有一个更深的理解. 2.NO ...
- 洛谷 P2253 好一个一中腰鼓! 题解
P2253 好一个一中腰鼓! 题目背景 话说我大一中的运动会就要来了,据本班同学剧透(其实早就知道了),我萌萌的初二年将要表演腰鼓[喷],这个无厘头的题目便由此而来. Ivan乱入:"忽一人 ...