Git Product home page Git Product logo

Comments (12)

fanliang11 avatar fanliang11 commented on May 21, 2024

姿势很正确,如果有缓存拦截的demo就更好了

from surging.

billyang avatar billyang commented on May 21, 2024

@fanliang11 其实我想把缓存拦截的写上去,刚在群里也看到了,但是有点小疑问,对“GetUserName_name_{0}“ 这个参数不理解

[InterceptMethod(CachingMethod.Remove, "GetUser_id_{0}", "GetUserName_name_{0}", CacheSectionType = SectionType.ddlCache, Mode = CacheTargetType.Redis)]

image

from surging.

fanliang11 avatar fanliang11 commented on May 21, 2024

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.

billyang avatar billyang commented on May 21, 2024

哎呀,我好像理解错了,抱歉。
在Remove模式下,"GetUser_id_{0}", "GetUserName_name_{0}" 移除的缓存是一个数组,我看成了是多个参数。。。

from surging.

billyang avatar billyang commented on May 21, 2024

我配的缓存拦截好像没起作用,没写入到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.

fanliang11 avatar fanliang11 commented on May 21, 2024

你需要设置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.

billyang avatar billyang commented on May 21, 2024

缓存还是没起作用,是写入到Redis没错吧。
要是有时间看下Bill.Demo.IModuleServicesBill.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.

fanliang11 avatar fanliang11 commented on May 21, 2024

已修复不能获取服务条目的BUG,请下载最新的代码

from surging.

billyang avatar billyang commented on May 21, 2024

你好,更新了代码出现了新的问题。Surging提供的Client跑起来没问题,但是在我的Web客户端有问题,
Client使用了ServiceHostBuilder,我的Web使用的是WebHostBuilder

发现使用ServiceHostBuilder 使用了

                .UseServiceCache()
                .UseProxy()
                .UseLog4net()
                .UseClient()

还麻烦看看Web下应该如何配置
再往下就不太会调试了

这是报错信息
image

from surging.

fanliang11 avatar fanliang11 commented on May 21, 2024

不要用.UseServiceCache(),请更新master版本,请用原来的配置

from surging.

billyang avatar billyang commented on May 21, 2024

更新了的。在 WebHostBuilder 使用不了 .UseServiceCache().UseProxy().UseLog4net().UseClient()

Surging.Services.Client 、Bill.Demo.Web 两者配置有些不同,Bill.Demo.Web我是根据Surging.ApiGateway来配的

from surging.

fanliang11 avatar fanliang11 commented on May 21, 2024

用你原来的配置。不要去更改任何配置

from surging.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.