-
Notifications
You must be signed in to change notification settings - Fork 87
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #66 from EasyAbp/fix-shared-redis
Made `SharedStackExchangeRedisAccessTokenCache` work
- Loading branch information
Showing
5 changed files
with
56 additions
and
56 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
53 changes: 53 additions & 0 deletions
53
...StackExchangeRedis/Infrastructure/AccessToken/SharedStackExchangeRedisAccessTokenCache.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
}); | ||
} | ||
} |
52 changes: 0 additions & 52 deletions
52
...ckExchangeRedis/Infrastructure/AccessToken/SharedStackExchangeRedisAccessTokenProvider.cs
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters