Skip to content

Commit

Permalink
Merge pull request #66 from EasyAbp/fix-shared-redis
Browse files Browse the repository at this point in the history
Made `SharedStackExchangeRedisAccessTokenCache` work
  • Loading branch information
gdlcf88 committed Dec 27, 2022
2 parents f099e6c + e351119 commit 5e766dd
Show file tree
Hide file tree
Showing 5 changed files with 56 additions and 56 deletions.
2 changes: 1 addition & 1 deletion common.props
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project>
<PropertyGroup>
<LangVersion>latest</LangVersion>
<Version>2.0.0-rc.21</Version>
<Version>2.0.0-rc.22</Version>
<NoWarn>$(NoWarn);CS1591</NoWarn>
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
<Authors>EasyAbp Team</Authors>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
<RootNamespace>EasyAbp.Abp.WeChat.Common.SharedCache.StackExchangeRedis</RootNamespace>
<Description>ABP vNext微信模块,基于StackExchangeRedis提供多服务间共享access_token等缓存数据的功能扩展。</Description>
<GenerateEmbeddedFilesManifest>true</GenerateEmbeddedFilesManifest>
<LangVersion>8</LangVersion>
</PropertyGroup>

<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
using System;
using System.Threading.Tasks;
using EasyAbp.Abp.WeChat.Common.Infrastructure.AccessToken;
using EasyAbp.Abp.WeChat.Common.SharedCache.StackExchangeRedis.Settings;
using Microsoft.Extensions.Caching.Distributed;
using Microsoft.Extensions.Caching.StackExchangeRedis;
using Volo.Abp.Caching.StackExchangeRedis;
using Volo.Abp.Settings;

namespace EasyAbp.Abp.WeChat.Common.SharedCache.StackExchangeRedis.Infrastructure.AccessToken;

public class SharedStackExchangeRedisAccessTokenCache : IAccessTokenCache
{
public static string CachePrefix { get; set; } = "WeChatTokens:";
public static string SettingName { get; set; } = SharedCacheStackExchangeRedisSettings.RedisConfiguration;

private readonly ISettingProvider _settingProvider;

public SharedStackExchangeRedisAccessTokenCache(ISettingProvider settingProvider)
{
_settingProvider = settingProvider;
}

public virtual async Task<string> GetOrNullAsync(string key)
{
var redisCache = await CreateAbpRedisCacheAsync();

return await redisCache.GetStringAsync(await GetKeyAsync(key));
}

public virtual async Task SetAsync(string key, string value)
{
var redisCache = await CreateAbpRedisCacheAsync();

await redisCache.SetStringAsync(await GetKeyAsync(key), value, new DistributedCacheEntryOptions
{
AbsoluteExpirationRelativeToNow = TimeSpan.FromMinutes(115)
});
}

protected virtual Task<string> GetKeyAsync(string key)
{
return Task.FromResult($"{CachePrefix}{key}");
}

protected virtual async Task<AbpRedisCache> CreateAbpRedisCacheAsync()
{
return new AbpRedisCache(new RedisCacheOptions
{
Configuration = await _settingProvider.GetOrNullAsync(SettingName)
});
}
}

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@

namespace EasyAbp.Abp.WeChat.Common.Infrastructure.AccessToken;

public class AccessTokenCache : IAccessTokenCache, ITransientDependency
public class DefaultAccessTokenCache : IAccessTokenCache, ITransientDependency
{
protected IDistributedCache<string> DistributedCache { get; }

public AccessTokenCache(IDistributedCache<string> distributedCache)
public DefaultAccessTokenCache(IDistributedCache<string> distributedCache)
{
DistributedCache = distributedCache;
}
Expand Down

0 comments on commit 5e766dd

Please sign in to comment.