You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@dubbo.apache.org by GitBox <gi...@apache.org> on 2021/08/28 08:41:32 UTC

[GitHub] [dubbo] gang0713 edited a comment on issue #8610: 建议增加对阿里jetcache缓存的支持,当把@Cached注解缓存定义在接口方法上时,不是先取缓存,还是通过RPC进行了远程调用。

gang0713 edited a comment on issue #8610:
URL: https://github.com/apache/dubbo/issues/8610#issuecomment-907594667


   @24kpure  最好是实现方法级别的缓存,https://github.com/qy8502/jetcache-plus/tree/master/jetcache-plus-dubbo
   
   3.1. 背景
   目前通过dubbo实现微服务,跨服务获取数据,往往先通过dubbo再到redis的方式获取数据。这样做在缓存可以命中的情况下多出了大约10ms的dubbo时间消耗和相应带宽消耗,比较浪费。需要调用者先写走redis再走dubbo。
   
   3.2. 实现方式
   利用 dubbo动态代理扩展 实现将服务消费者的代理实例,再包装一层代理实现缓存注解的拦截的处理。
   
   通过JetCacheDubboProxyFactoryWrapper实现ProxyFactory接口,根据是否是包含缓存的服务,不是直接返回dubbo代理,是创建三层缓存代理:
   
   第一层代理仅仅为了判断是否是@Cached注解方法,如果不是直接dubbo调用,@CacheInvalidate或@CacheUpdate都应当由远端服务处理完逻辑后处理缓存,不在此多管闲事。
   如果是@Cached注解方法,通过JetCacheInterceptor创建第二层的缓存代理类,调用时处理缓存。
   缓存未命中时,进入第三层代理,判断方法是否default方法体,如果是直接执行default逻辑,不是则执行dubbo调用。 这种设计提供了一种解决方案,服务声明两个方法getXxx和getXxxNoCache之类,前者注解@Cached且defaulte方法体调用后者,后者的实现处理具体业务逻辑。 这样使得dubbo消费者调用getXxx时,在消费者端执行缓存处理。 缓存如果未命中,在消费者端就转为dubbo调用getXxxNoCache方法。避免在服务提供端调用getXxx再执行一遍缓存处理逻辑。
   switcher proxy
   ┌──────────────────────────────────────────────────┐
   │  @Cached method         /       other            │
   │         │                         │              │
   │         │                         │              │
   │         ▼                         │              │
   │  cache interceptor proxy          │              │
   │  ┌────────────────────────────────┼───────────┐  │
   │  │  handle cache                  │           │  │
   │  │       │                        │           │  │
   │  │       │                        │           │  │
   │  │       ▼                        │           │  │
   │  │  default method proxy          │           │  │
   │  │  ┌─────────────────────────────┼────────┐  │  │
   │  │  │  is default method    /     │ other  │  │  │
   │  │  │      │                      │    │   │  │  │
   │  │  │      │                      │    │   │  │  │
   │  │  │      │                      ▼    ▼   │  │  │
   │  │  │      │             dubbo proxy       │  │  │
   │  │  │      │             ┌──────────────┐  │  │  │
   │  │  │      ▼             │  rpc         │  │  │  │
   │  │  │  default method ──►│              │  │  │  │
   │  │  │                    │              │  │  │  │
   │  │  │                    └──────────────┘  │  │  │
   │  │  │                                      │  │  │
   │  │  └──────────────────────────────────────┘  │  │
   │  │                                            │  │
   │  └────────────────────────────────────────────┘  │
   │                                                  │
   └──────────────────────────────────────────────────┘


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@dubbo.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@dubbo.apache.org
For additional commands, e-mail: notifications-help@dubbo.apache.org