-
Notifications
You must be signed in to change notification settings - Fork 4.4k
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 #3054 from JeffreySu/Developer
发布新版本:Senparc.Weixin.Cache.Dapr v0.1.0-beta1
- Loading branch information
Showing
8 changed files
with
359 additions
and
2 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
204 changes: 204 additions & 0 deletions
204
...ixin.Cache/Senparc.Weixin.Cache.Dapr/ContainerCacheStrategy/DaprContainerCacheStrategy.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,204 @@ | ||
#region Apache License Version 2.0 | ||
/*---------------------------------------------------------------- | ||
Copyright 2024 Jeffrey Su & Suzhou Senparc Network Technology Co.,Ltd. | ||
Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file | ||
except in compliance with the License. You may obtain a copy of the License at | ||
http://www.apache.org/licenses/LICENSE-2.0 | ||
Unless required by applicable law or agreed to in writing, software distributed under the | ||
License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, | ||
either express or implied. See the License for the specific language governing permissions | ||
and limitations under the License. | ||
Detail: https://github.com/JeffreySu/WeiXinMPSDK/blob/master/license.md | ||
----------------------------------------------------------------*/ | ||
#endregion Apache License Version 2.0 | ||
|
||
/*---------------------------------------------------------------- | ||
Copyright (C) 2024 Senparc | ||
文件名:DaprContainerCacheStrategy.cs | ||
文件功能描述:Redis 容器缓存策略。 | ||
创建标识:Senparc - 20160308 | ||
修改标识:Senparc - 20160808 | ||
修改描述:v0.2.0 删除 ItemCollection 属性,直接使用ContainerBag加入到缓存 | ||
修改标识:Senparc - 20160812 | ||
修改描述:v0.2.1 解决Container无法注册的问题 | ||
修改标识:Senparc - 20170205 | ||
修改描述:v0.2.0 重构分布式锁 | ||
----------------------------------------------------------------*/ | ||
|
||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Threading.Tasks; | ||
using Senparc.CO2NET.Cache; | ||
using Senparc.CO2NET.Cache.Dapr; | ||
using Senparc.CO2NET.Cache.Dapr.ObjectCacheStrategy; | ||
using Senparc.CO2NET.Helpers; | ||
using Senparc.CO2NET.MessageQueue; | ||
using Senparc.Weixin.Containers; | ||
using Senparc.Weixin.Helpers; | ||
|
||
|
||
namespace Senparc.Weixin.Cache.Dapr | ||
{ | ||
/// <summary> | ||
/// Redis容器缓存策略 | ||
/// </summary> | ||
public sealed class DaprContainerCacheStrategy : BaseContainerCacheStrategy | ||
{ | ||
#region IDomainExtensionCacheStrategy 成员 | ||
public override ICacheStrategyDomain CacheStrategyDomain { get { return ContainerCacheStrategyDomain.Instance; } } | ||
|
||
#endregion | ||
|
||
#region 单例 | ||
|
||
/// <summary> | ||
/// Redis 缓存策略 | ||
/// </summary> | ||
DaprContainerCacheStrategy() /*: base()*/ | ||
{ | ||
//base.ChildNamespace = "WeixinContainer"; | ||
|
||
//使用底层缓存策略 | ||
BaseCacheStrategy = () => DaprStateObjectCacheStrategy.Instance; | ||
|
||
//向底层缓存注册当前缓存策略 | ||
base.RegisterCacheStrategyDomain(this); | ||
} | ||
|
||
|
||
//静态SearchCache | ||
public static DaprContainerCacheStrategy Instance | ||
{ | ||
get | ||
{ | ||
return Nested.instance;//返回Nested类中的静态成员instance | ||
} | ||
} | ||
|
||
class Nested | ||
{ | ||
static Nested() | ||
{ | ||
} | ||
//将instance设为一个初始化的BaseCacheStrategy新实例 | ||
internal static readonly DaprContainerCacheStrategy instance = new DaprContainerCacheStrategy(); | ||
} | ||
|
||
#endregion | ||
|
||
static DaprContainerCacheStrategy() | ||
{ | ||
} | ||
|
||
/// <summary> | ||
/// Redis 缓存策略析构函数,用于 _client 资源回收 | ||
/// </summary> | ||
~DaprContainerCacheStrategy() | ||
{ | ||
} | ||
|
||
#region 实现 IContainerCacheStrategy 接口 | ||
|
||
/// <summary> | ||
/// 获取所有 Bag 对象 | ||
/// </summary> | ||
/// <typeparam name="TBag"></typeparam> | ||
/// <returns></returns> | ||
public override IDictionary<string, TBag> GetAll<TBag>() | ||
{ | ||
#region 旧方法(没有使用Hash之前) | ||
|
||
//var itemCacheKey = ContainerHelper.GetItemCacheKey(typeof(TBag), "*"); | ||
////var keyPattern = string.Format("*{0}", itemCacheKey); | ||
//var keyPattern = GetFinalKey(itemCacheKey); | ||
|
||
//var keys = GetServer().Keys(pattern: keyPattern); | ||
//var dic = new Dictionary<string, TBag>(); | ||
//foreach (var redisKey in keys) | ||
//{ | ||
// try | ||
// { | ||
// var bag = Get(redisKey, true); | ||
// dic[redisKey] = (TBag)bag; | ||
// } | ||
// catch (Exception) | ||
// { | ||
|
||
// } | ||
|
||
//} | ||
|
||
#endregion | ||
|
||
|
||
throw new NotImplementedException(); | ||
|
||
//var baseCacheStrategy = BaseCacheStrategy(); | ||
//var key = ContainerHelper.GetItemCacheKey(typeof(TBag), ""); | ||
//key = key.Substring(0, key.Length - 1);//去掉:号 | ||
//key = baseCacheStrategy.GetFinalKey(key);//获取带SenparcWeixin:DefaultCache:前缀的Key([DefaultCache]可配置) | ||
//var list = (baseCacheStrategy as DaprStateObjectCacheStrategy).GetAllByPrefix<TBag>(key); | ||
|
||
////var list = (baseCacheStrategy as RedisObjectCacheStrategy).GetAll(key); | ||
//var dic = new Dictionary<string, TBag>(); | ||
|
||
//foreach (var item in list) | ||
//{ | ||
// var fullKey = key + ":" + item.Key;//最完整的finalKey(可用于LocalCache),还原完整Key,格式:[命名空间]:[Key] | ||
// //dic[fullKey] = StackExchangeRedisExtensions.Deserialize<TBag>(hashEntry.Value); | ||
// dic[fullKey] = item; | ||
//} | ||
|
||
//return dic; | ||
} | ||
|
||
|
||
#region 异步方法 | ||
|
||
/// <summary> | ||
/// 【异步方法】获取所有 Bag 对象 | ||
/// </summary> | ||
/// <typeparam name="TBag"></typeparam> | ||
/// <returns></returns> | ||
public override async Task<IDictionary<string, TBag>> GetAllAsync<TBag>() | ||
{ | ||
throw new NotImplementedException(); | ||
//var baseCacheStrategy = BaseCacheStrategy(); | ||
//var key = ContainerHelper.GetItemCacheKey(typeof(TBag), ""); | ||
//key = key.Substring(0, key.Length - 1);//去掉:号 | ||
//key = baseCacheStrategy.GetFinalKey(key);//获取带SenparcWeixin:DefaultCache:前缀的Key([DefaultCache]可配置) | ||
//var list = await (baseCacheStrategy as DaprStateObjectCacheStrategy).GetAllByPrefixAsync<TBag>(key).ConfigureAwait(false); | ||
|
||
////var list = (baseCacheStrategy as RedisObjectCacheStrategy).GetAll(key); | ||
//var dic = new Dictionary<string, TBag>(); | ||
|
||
//foreach (var item in list) | ||
//{ | ||
// var fullKey = key + ":" + item.Key;//最完整的finalKey(可用于LocalCache),还原完整Key,格式:[命名空间]:[Key] | ||
// //dic[fullKey] = StackExchangeRedisExtensions.Deserialize<TBag>(hashEntry.Value); | ||
// dic[fullKey] = item; | ||
//} | ||
|
||
//return dic; | ||
} | ||
|
||
#endregion | ||
|
||
#endregion | ||
|
||
} | ||
} |
49 changes: 49 additions & 0 deletions
49
src/Senparc.Weixin.Cache/Senparc.Weixin.Cache.Dapr/Register.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,49 @@ | ||
/*---------------------------------------------------------------- | ||
Copyright (C) 2024 Senparc | ||
文件名:Register.cs | ||
文件功能描述:Senparc.Weixin.Cache.Redis 注册类 | ||
创建标识:Senparc - 20180609 | ||
修改标识:Senparc - 20180802 | ||
修改描述:当前类所有方法支持 .net standard 2.0 | ||
修改标识:Senparc - 20191002 | ||
修改描述:v2.7.102 RegisterDomainCache() 方法重命名为 ActivityDomainCache() | ||
修改标识:Senparc - 20191002 | ||
修改描述:v2.8.100 UseSenparcWeixinCacheRedis() 扩展方法 this 类型由 IApplicationBuilder 改为 IRegisterService | ||
----------------------------------------------------------------*/ | ||
|
||
using Senparc.CO2NET.RegisterServices; | ||
|
||
namespace Senparc.Weixin.Cache.Dapr | ||
{ | ||
/// <summary> | ||
/// Senparc.Weixin.Cache.Redis 注册类 | ||
/// </summary> | ||
public static class Register | ||
{ | ||
/// <summary> | ||
/// 注册 Senparc.Weixin.Cache.Redis | ||
/// </summary> | ||
/// <param name="register"></param> | ||
public static IRegisterService UseSenparcWeixinCacheDapr(this IRegisterService register) | ||
{ | ||
ActivityDomainCache(); | ||
return register; | ||
} | ||
|
||
/// <summary> | ||
/// 激活领域缓存 | ||
/// </summary> | ||
public static void ActivityDomainCache() | ||
{ | ||
//通过调用 ContainerCacheStrategy,激活领域模型注册过程 | ||
var cache = DaprContainerCacheStrategy.Instance; | ||
} | ||
} | ||
} |
67 changes: 67 additions & 0 deletions
67
src/Senparc.Weixin.Cache/Senparc.Weixin.Cache.Dapr/Senparc.Weixin.Cache.Dapr.net8.csproj
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,67 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
<PropertyGroup> | ||
<TargetFrameworks>net8.0</TargetFrameworks> | ||
<Version>0.1.0-beta1</Version> | ||
<AssemblyName>Senparc.Weixin.Cache.Dapr</AssemblyName> | ||
<RootNamespace>Senparc.Weixin.Cache.Dapr</RootNamespace> | ||
<GeneratePackageOnBuild Condition=" '$(Configuration)' == 'Release' ">true</GeneratePackageOnBuild> | ||
<Description> | ||
微信 SDK - Redis 模块 | ||
|
||
Senparc.Weixin SDK 开源项目: | ||
https://github.com/JeffreySu/WeiXinMPSDK | ||
</Description> | ||
<Copyright>Senparc Copyright © 2004~2024</Copyright> | ||
<PackageTags>微信,weixin,公众号,WeChat,Senparc,盛派,SDK,C#,JSSDK,微信支付,分布式,小程序,Cache,Redis</PackageTags> | ||
<Authors>Jeffrey Su</Authors> | ||
<Owners>Senparc</Owners> | ||
<PackageLicenseExpression>Apache-2.0</PackageLicenseExpression> | ||
<ProjectUrl>https://github.com/JeffreySu/WeiXinMPSDK</ProjectUrl> | ||
<Title>Senparc.Weixin.Cache.Dapr.dll</Title> | ||
<Summary>微信 SDK for .NET / C#</Summary> | ||
<PackageProjectUrl>https://github.com/JeffreySu/WeiXinMPSDK</PackageProjectUrl> | ||
<PackageIcon>icon.jpg</PackageIcon> | ||
<PackageReleaseNotes> | ||
v0.1.0 | ||
创世 | ||
</PackageReleaseNotes> | ||
<RepositoryUrl>https://github.com/JeffreySu/WeiXinMPSDK</RepositoryUrl> | ||
</PropertyGroup> | ||
<PropertyGroup Condition=" '$(Configuration)' == 'Release' "> | ||
<OutputPath>..\..\BuildOutPut</OutputPath> | ||
<DefineConstants>TRACE</DefineConstants> | ||
</PropertyGroup> | ||
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Release|x86'"> | ||
<OutputPath>..\..\BuildOutPut</OutputPath> | ||
<DefineConstants>$(DefineConstants);RELEASE</DefineConstants> | ||
<DocumentationFile>..\..\BuildOutPut\Senparc.Weixin.Cache.Dapr.XML</DocumentationFile> | ||
<Optimize>true</Optimize> | ||
<DebugType>pdbonly</DebugType> | ||
<ErrorReport>prompt</ErrorReport> | ||
<CodeAnalysisRuleSet>MinimumRecommendedRules.ruleset</CodeAnalysisRuleSet> | ||
</PropertyGroup> | ||
<PropertyGroup Condition="'$(Configuration)|$(TargetFramework)|$(Platform)'=='Release|net462|AnyCPU'"> | ||
<OutputPath>..\..\BuildOutPut\</OutputPath> | ||
<DocumentationFile>..\..\BuildOutPut\net462\Senparc.Cache.Dapr.xml</DocumentationFile> | ||
</PropertyGroup> | ||
<PropertyGroup Condition="'$(Configuration)|$(TargetFramework)|$(Platform)'=='Release|netstandard2.0|AnyCPU'"> | ||
<OutputPath>..\..\BuildOutPut\</OutputPath> | ||
<DocumentationFile>..\..\BuildOutPut\netstandard2.0\Senparc.Cache.Dapr.xml</DocumentationFile> | ||
</PropertyGroup> | ||
<PropertyGroup Condition="'$(Configuration)|$(TargetFramework)|$(Platform)'=='Release|netstandard2.1|AnyCPU'"> | ||
<OutputPath>..\..\BuildOutPut\</OutputPath> | ||
<DocumentationFile>..\..\BuildOutPut\netstandard2.1\Senparc.Cache.Dapr.xml</DocumentationFile> | ||
</PropertyGroup> | ||
<ItemGroup> | ||
<None Include="..\..\Senparc.Weixin\icon.jpg" Pack="true" Visible="false" PackagePath="" /> | ||
</ItemGroup> | ||
<ItemGroup> | ||
<PackageReference Include="Senparc.CO2NET.Cache.Dapr" Version="0.1.0" /> | ||
</ItemGroup> | ||
<ItemGroup> | ||
<ProjectReference Include="..\..\Senparc.Weixin\Senparc.Weixin\Senparc.Weixin.net8.csproj" /> | ||
</ItemGroup> | ||
<ItemGroup> | ||
<PackageReference Update="Microsoft.SourceLink.GitHub" Version="1.1.1" /> | ||
</ItemGroup> | ||
</Project> |
11 changes: 11 additions & 0 deletions
11
src/Senparc.Weixin.Cache/Senparc.Weixin.Cache.Dapr/app.config
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,11 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<configuration> | ||
<runtime> | ||
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1"> | ||
<dependentAssembly> | ||
<assemblyIdentity name="Newtonsoft.Json" publicKeyToken="30ad4fe6b2a6aeed" culture="neutral" /> | ||
<bindingRedirect oldVersion="0.0.0.0-12.0.0.0" newVersion="12.0.0.0" /> | ||
</dependentAssembly> | ||
</assemblyBinding> | ||
</runtime> | ||
</configuration> |
Oops, something went wrong.