Comments (12)
姿势很正确,如果有缓存拦截的demo就更好了
from surging.
@fanliang11 其实我想把缓存拦截的写上去,刚在群里也看到了,但是有点小疑问,对“GetUserName_name_{0}“ 这个参数不理解
[InterceptMethod(CachingMethod.Remove, "GetUser_id_{0}", "GetUserName_name_{0}", CacheSectionType = SectionType.ddlCache, Mode = CacheTargetType.Redis)]
from surging.
1.传递的方法参数如果是model类型,就需要设置 [CacheKey(1)]来标识缓存key, 比如传递UserModel,
设置UserId 为1,Name 为fanly, 设置的KEY为GetUserName_name_{1}
那么缓存的key就会生成GetUserName_name_fanly, key 如果设置为GetUserName_id_{0}
那么缓存的key就会生成GetUserName_id_1
2. 传递的方法参数是string,int 类型就不需要设置 [CacheKey(1)]
[ProtoContract]
public class UserModel
{
[CacheKey(1)]
public int UserId { get; set; }
[CacheKey(2)]
public string Name { get; set; }
public int Age { get; set; }
}
from surging.
哎呀,我好像理解错了,抱歉。
在Remove模式下,"GetUser_id_{0}", "GetUserName_name_{0}" 移除的缓存是一个数组,我看成了是多个参数。。。
from surging.
我配的缓存拦截好像没起作用,没写入到Redis,是不是哪里还需要配置?拦截器配置我看到示例是放到Client 和ApiGateway
IUserService
[InterceptMethod(CachingMethod.Get, Key = "GetUser_id_{0}", CacheSectionType = SectionType.ddlCache, Mode = CacheTargetType.Redis, Time = 480)]
Task<UserDto> GetUserById(Int64 id);
[InterceptMethod(CachingMethod.Put, Key = "GetUser_id_{0}", CacheSectionType = SectionType.ddlCache, Mode = CacheTargetType.Redis)]
Task<Boolean> UpdateUser(UserDto user);
[InterceptMethod(CachingMethod.Remove, "GetUser_id_{0}", CacheSectionType = SectionType.ddlCache, Mode = CacheTargetType.Redis)]
Task<Boolean> DeleteUser(Int64 userId);
UserDto
[ProtoContract]
public class UserDto
{
[ProtoMember(1)]
[CacheKey(1)]
public long Id { get; set; }
[ProtoMember(2)]
public string PhoneNumber { get; set; }
[ProtoMember(3)]
public string Name { get; set; }
}
from surging.
你需要设置RequestCacheEnabled = true和 option.AddClientIntercepted(typeof(CacheProviderInterceptor));
[Command(Strategy = StrategyType.Failover, RequestCacheEnabled = true, InjectionNamespaces = new string[] { "Surging.IModuleServices.Common" })]
builder.AddMicroService(option =>
{
option.AddClient();
option.AddClientIntercepted(typeof(CacheProviderInterceptor));
//option.UseZooKeeperManager(new ConfigInfo("127.0.0.1:2181"));
option.UseConsulManager(new ConfigInfo("127.0.0.1:8500"));
option.UseDotNettyTransport();
option.UseRabbitMQTransport();
//option.UseKafkaMQTransport(kafkaOption =>
//{
// kafkaOption.Servers = "127.0.0.1";
//});
//option.UseProtoBufferCodec();
option.UseMessagePackCodec();
builder.Register(p => new CPlatformContainer(ServiceLocator.Current));
});
from surging.
缓存还是没起作用,是写入到Redis没错吧。
要是有时间看下Bill.Demo.IModuleServices,Bill.Demo.Services.Server 看看配置是否正确,谢谢哈
[Service(Date = "2018-3-2", Director = "Bill", Name = "获取用户信息")]
[Command(Strategy = StrategyType.Failover, RequestCacheEnabled = true, InjectionNamespaces = new string[] { "Bill.Demo.IModuleServices.Users" })]
[InterceptMethod(CachingMethod.Get, Key = "GetUser_id_{0}", CacheSectionType = SectionType.ddlCache, Mode = CacheTargetType.Redis, Time = 480)]
Task<UserDto> GetUserById(Int64 id);
from surging.
已修复不能获取服务条目的BUG,请下载最新的代码
from surging.
你好,更新了代码出现了新的问题。Surging提供的Client跑起来没问题,但是在我的Web客户端有问题,
Client使用了ServiceHostBuilder,我的Web使用的是WebHostBuilder
发现使用ServiceHostBuilder 使用了
.UseServiceCache()
.UseProxy()
.UseLog4net()
.UseClient()
还麻烦看看Web下应该如何配置
再往下就不太会调试了
from surging.
不要用.UseServiceCache(),请更新master版本,请用原来的配置
from surging.
更新了的。在 WebHostBuilder 使用不了 .UseServiceCache().UseProxy().UseLog4net().UseClient()
Surging.Services.Client 、Bill.Demo.Web 两者配置有些不同,Bill.Demo.Web我是根据Surging.ApiGateway来配的
from surging.
用你原来的配置。不要去更改任何配置
from surging.
Related Issues (20)
- 两个不同的Modules项目中如何相互调用 HOT 1
- hh
- 单服务热加载问题 HOT 3
- 用jmeter对sayhello做压力测试时,返回结果不一致,entity为1 HOT 1
- k8s
- k8s中单服务重发之后 提示如下 HOT 3
- The community version is the last version. HOT 3
- new feature Protokollwandler component will be updated in SurgingVista version
- 统计一下有多少人使用社区版 HOT 1
- Hot deployment modules and components
- 请问Surging 中使用的 WebSocketCore 的源码是这个地址吗 HOT 1
- server进程占用的内存一直增长,直到进程崩溃,是什么原因? HOT 11
- NLog HOT 6
- surgingSettings.json配置中的Consul 连接ConnectionString配置 HOT 1
- Surging.Core.KestrelHttpServer HOT 1
- 请求参数
- 开源**NCC介绍 HOT 4
- 使用serviceProxyProvider.Invoke调用接口内存持续增长 HOT 4
- TCP network components that support configuring properties
- 服务间通讯导致内存持续增加 HOT 5
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from surging.