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),而是一个对缓存使 ...
随机推荐
- h5表单亲测
Document 下载进度: 标签. 牛奶 面包 男 女 one two three 按钮 搜索 请输入搜索内容 加密强度 用户名 Email 密码 年龄 身高 生日 这一系列是很酷的一个类型,完全解 ...
- 微信小程序到底把什么定义为风险内容?
目录 起因 经过和结果 附录: 起因 之前做一个群相册的小程序,因为涉及到图片和评论等内容的发布分享.因此,微信后台要求有一定的内容安全检测能力. 但是,我用别家的内容检测用的好好的,在国庆前被微信警 ...
- Alipay 支付宝SDK PHP Fatal error: Class 'LtObjectUtil' not found in。
在linux 上运行报错:PHP Fatal error: Class 'LtObjectUtil' not found in. 这是因为人家用的lotusphp框架,和你正在使用的框架冲突了!比如 ...
- The 2019 Asia Nanchang First Round Online Programming Contest E. Magic Master
题目链接:https://nanti.jisuanke.com/t/41352 题目意思还是好理解的,看过的人不多,感觉是被通过量吓到了.其实就是个水题,反向模拟就好了, 用队列模拟,反向模拟,它要放 ...
- 一天撸完《 Learning Jupyter 5 2nd Edition》
因为工作需要了解这个应用的大概功能. 网上找不到下载的,CSDN没积分. 最后,在道客上找到了这个PDF.花了一天时间浏览了一下, 只留意了python功能,其它语言略去. widget和jupyte ...
- Xcode添加库文件framework (转)
首先需要了解一下iOS中静态库和动态库.framework的概念 静态库与动态库的区别 首先来看什么是库,库(Library)说白了就是一段编译好的二进制代码,加上头文件就可以供别人使用. 什么时候我 ...
- Python 字符串内置方法笔记
一. 大小写转换 ① capitalize() capitalize() #字符串首字母大写 >>> str0 = 'hello World' >>> str0.c ...
- 07-numpy-笔记-join
字符串.join(字符串序列) 一目了然: #!/usr/bin/python # -*- coding: UTF-8 -*- str = "-"; seq = ("a& ...
- CNCF LandScape Summary
CNCF Cloud Native Interactive Landscape 1. App Definition and Development 1. Database Vitess:itess i ...
- hdu1873-看病要排队-(结构体优先队列)
http://acm.hdu.edu.cn/showproblem.php?pid=1873 #include<stdio.h> #include<iostream> #inc ...